问题
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.
回答1:
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.
回答2:
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.
- 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.
- 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.
- 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"
回答3:
I'm using VS 2012 and ReSharper 7 and sometimes I found the same behavior. These are the steps that worked for me:
- Clean Solution
- Close Visual Studio
- Go to the root folder of your solution and find a folder called _ReSharper.[Name of your solution] and delete it.
- Go back to Visual Studio, open up your solution the folder gets recreated and no more "ambiguous reference" errors after that.
回答4:
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.
回答5:
ReSharper -> Options -> General: Click # Clear Caches # button.
回答6:
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.
回答7:
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#).
回答8:
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.
回答9:
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.
回答10:
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:
- False "Ambiguous reference" for symbols from App_Code
- Custom build provider may generate partial class with second part residing in app_code
回答11:
I had same problem with ReSharper 5.1 and solved it by restarting Visual Studio 2010.
回答12:
Using VS 2013 Premium & Resharper 8.1, and was getting this problem on an ASP.Net project.
The solution that worked for me:
- Do a clean Solution.
- Open references for the offending project
- On each reference that refers to another project in the solution, set
Copy Local = false. - Attempt a Rebuild Solution. You will likely get unresolved reference errors - that's normal.
- Set each reference back to
Copy Local = true(where appropriate)
回答13:
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.
来源:https://stackoverflow.com/questions/191950/how-to-resolve-incorrect-ambiguous-reference-from-resharper-on-class-inheritan