Carlton Jenke
Carlton Jenke

Reputation: 3025

How to resolve incorrect "Ambiguous reference" from ReSharper on class inheritance?

In my project I have a class that is inherited by many other classes. We'll call it ClassBase.

public class ClassInheritFromBase : ClassBase

When ClassBase is being inherited, ReSharper throws an "Ambiguous reference" warning on the ClassBase, and anything inside the new class that inherited from ClassBase does not have IntelliSense and gets warnings that it cannot find it.

The project compiles and runs fine.

If I change the namespace ClassBase is in and then change the inheriting classes, they find it fine and ReSharper has no problem, IntelliSense works ... until it is compiled. After the compile it goes back to having the ambiguous reference warnings and everything else.

Has this been seen before and how can it be fixed? I saw an entry in JetBrains bug tracking for an issue just like this, but they closed it as unable to reproduce.

Upvotes: 30

Views: 21588

Answers (14)

July.Tech
July.Tech

Reputation: 1376

In VS2022, simply cleaning the solution resolved the errors for me.

Upvotes: 0

Dave Cousineau
Dave Cousineau

Reputation: 13158

With R# 2019.2.3 and using the new SDK .csproj format, which splits references between .NET references, NUGET packages, and project dependencies, there is a tendency for R# to still add a project reference under Assemblies, even when there is already a project reference under Dependencies. This results in the ambiguity error but can be hard to notice since the reference is in two separate places. Look for any project references that appear under Assemblies and remove them.

Upvotes: 2

HiredMind
HiredMind

Reputation: 1857

Using VS 2013 Premium & Resharper 8.1, and was getting this problem on an ASP.Net project.

The solution that worked for me:

  1. Do a clean Solution.
  2. Open references for the offending project
  3. On each reference that refers to another project in the solution, set Copy Local = false.
  4. Attempt a Rebuild Solution. You will likely get unresolved reference errors - that's normal.
  5. Set each reference back to Copy Local = true (where appropriate)

Upvotes: 0

Evan
Evan

Reputation: 497

You may really have an ambiguous reference. In the project where the ambiguous reference error occurs, make sure to check in your project references. You might have the same reference twice but scoped through different namespaces. In my case there were two, but with different paths (example):

XXX.YYY.ZZZ.myassembly
ZZZ.myassembly

Make sure you don't have this kind of thing in your references.

Upvotes: 2

Peter
Peter

Reputation: 155

I deleted the _ReSharper.SolutionName folder found in the root of my solution and restarted.

I was using Visual Studio 2010 with ReSharper 5.1... Clearing the cache DID NOT help (ReSharper -> menu Options -> General -> #Clear Cache#).

Upvotes: 1

Andreas Presthammer
Andreas Presthammer

Reputation: 1990

I had same problem with ReSharper 5.1 and solved it by restarting Visual Studio 2010.

Upvotes: 0

Dennito
Dennito

Reputation: 280

I encountered the same problem. The issue I had was caused by a custom build provider (from an open source library I'm using called PageMethods) and the fact that all my .aspx pages inherit from a BasePage class which lives in the App_Code folder.

I couldn't get any build of ReSharper to work with my project (4.1.933, 4.1.943 (latest) or 4.5). The fix in the latest ReSharper build fixes the "Ambiguous Reference" problem, but breaks the custom build provider.

The only way I could get both the build provider and base classes to work with ReSharper was to put the Base Classes into a separate class library.

The following are the logged Jira bugs that seem to relate to this issue:

Upvotes: 0

David Fletcher
David Fletcher

Reputation:

I've seen this bug in ReSharper 4.1. It happens when the base class is in the App_Code directory. I don't know how to fix it; it is very annoying, but the code still compiles though.

Upvotes: 3

terjetyl
terjetyl

Reputation: 9565

This is a bug in ReSharper 4.1 and is fixed in one of the later nightly builds.

Download the last nightly build at http://www.jetbrains.net/confluence/display/ReSharper/ReSharper+4.0+Nightly+Builds.

Upvotes: 1

Miguel
Miguel

Reputation: 1714

I'm using VS 2012 and ReSharper 7 and sometimes I found the same behavior. These are the steps that worked for me:

  1. Clean Solution
  2. Close Visual Studio
  3. Go to the root folder of your solution and find a folder called _ReSharper.[Name of your solution] and delete it.
  4. Go back to Visual Studio, open up your solution the folder gets recreated and no more "ambiguous reference" errors after that.

Upvotes: 5

MortenRøgenes
MortenRøgenes

Reputation: 696

For those who still have a problem with this, (I still get it from time to time) here's the steps I did to get rid of the ambiguous reference warning in ReSharper.

  1. First I went to all my class libraries and made sure that all references to my other class libraries had the Copy Local property set to false.
  2. In the project where I actually got the ambiguous reference warning, I went to my bin catalog and deleted all .dll and .pdb files for all the libraries that had their own project.
  3. After a new build, or in my case "update reference" on the .dll files in VS, the errors from Resharper were gone.

I'm using Resharper 5.1 in Visual Studio 2008 with only a reference to the dlls I'm using which is why I had to "update reference"

Upvotes: 17

Henrik
Henrik

Reputation: 9915

For me it was a matter of me not using the solution folder for caches. Changing it from the TEMP location to in the solution solved my problem.

Upvotes: 1

Gokce Mutlu
Gokce Mutlu

Reputation: 101

ReSharper -> Options -> General: Click # Clear Caches # button.

Upvotes: 1

Jonathan Williams
Jonathan Williams

Reputation: 2055

I was experiencing the same problem with references to C# classes in the AppCode folder.

I resolved this by upgrading my ReSharper to version 4.5 (from version 4.1).

It was a very simple upgrade, I just had to get the latest version from the JetBrains website (http://www.jetbrains.com/resharper/download/) and run it.

I did not have to uninstall the previous version (v4.1). I did not have to re-enter my existing licence key.

All references are now recognised correctly and I can naviage to the classes as expected.

Upvotes: 0

Related Questions