Ambiguous references with the exact same namespace

C#asp.net Mvc-3Ef Code-FirstResharper

C# Problem Overview


The RC class is not linked to a database, it is a simple class. The class is at only one place and is not partial. The AĆ©rochem.Domain dll project compiles just fine.

Note: If I select one of the two identical namespaces in the quick fix menu, it does nothing.

Note2: This happens to a couple of classes (some related to a database, some not)

Is there a fix to that or a way to figure what's wrong?

enter image description here

C# Solutions


Solution 1 - C#

I had the same problem. I use ReSharper. The solution to my problem was not cleaning the solution but deleting the suo-file. Hope that helps.

Solution 2 - C#

As for the reference of any future users: This thread covers four answers whereas two are in the comments. I have faced the issue several times, three of these answers have helped me in the past, so if you face the same issue, try any of these:

  • Clean and/or Rebuild the Solution then reanalyze the files in Resharper.
  • Restart Visual Studio then reanalyze
  • Delete the bin/ folder then reanalyze
  • (Apparently deleting the suo-file can help, too, although I never had to do that and can't understand how it should help)
  • A combination of the three above.

(This is not really a new answer, it is more of a comment on the variety of answers and comments found - it is a community wiki so feel free to adapt it if necessary)

Solution 3 - C#

For ReSharper users that, like me, don't want to delete their solution's *.suo file:

Clear your caches via: ReSharper -> Options -> Environment -> General -> Clear Caches!

Clear ReSharper caches

Thanks go to AUSTX_RJL for his comment to this answer. I wanted to give his valuable info more visibility.

Solution 4 - C#

The .dll was already in my /bin folder.

When I deleted it, it got rid of this error.

Solution 5 - C#

I had this problem and also ReSharper installed on visual studio.

Print screen 1

Print screen 2

I open bug ticket on ReSharper tracker and the development team advised me to do:

Solution:

This problem can be solved by removing the Solution User Options (.Suo) File. This file is stored in the project root but is hidden. you need to check Folder Options-> View-> Show hidden files, folders, drives. and you need to close visual studio if you have open this project because is used by visual studio.

Solution 6 - C#

For me it was because I had referenced the DLL both by Project reference and Assembly reference. Deleting the Assembly reference fixed the issue.

Solution 7 - C#

I had the same problem while two packages were ambiguously referencing the same dll, and this is what worked for me:

I have given an alias name to one of the packages (named Dapper.StrongName), by putting the following into my .csproj file:

  <Target Name="ChangeNameAlias" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
    <ItemGroup>
      <ReferencePath Condition="'%(FileName)' == 'Dapper.StrongName'">
        <Aliases>AliasName</Aliases>
      </ReferencePath>
    </ItemGroup>
  </Target>

And then added the namespace as using AliasName::Dapper;

I added a post here: Ambiguous extension methods

See related articles:

Solution 8 - C#

If your project structure contains more than one project under one solution, then you have to delete the content of the bin folder in every project. Doing so solved the error that i was facing.

Solution 9 - C#

In my case, i have referenced the proyect X inside itself. So the problem wasn't ReSharper (but it was ReSharper who added the reference...)

Solution 10 - C#

I had this problem in a .NET standard project (I call it the host project). The namespace causing the problem was in another referenced project (which was also a .NET standard project) in the same solution.

I did everything: clean, delete resharper cache, close soln, delete .suo, delete binaries. Nothing seemed to work.

Then I converted the host project to .NET framework and then the problem disappeared.

Solution 11 - C#

I know this is a pretty old issue, but maybe this will help someone. If using c# razor in Asp.Net Core 2+, if you have this problem.

  1. Copy the content of the file to notepad.

  2. Delete the .cshtml file.

  3. Create the .cshtml file with the same name.

  4. Copy the content from notepad into the new file

I don't know if this is just a weird bug, or a consequence of upgrading a project from Core 1.0 to 2+, but it FINALLY fixed the problem for me. This was an issue for me in both Visual Studio 2017 and 2019.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMathieuView Question on Stackoverflow
Solution 1 - C#Michael MaireggerView Answer on Stackoverflow
Solution 2 - C#chiccodoroView Answer on Stackoverflow
Solution 3 - C#OliverView Answer on Stackoverflow
Solution 4 - C#Nathan KoopView Answer on Stackoverflow
Solution 5 - C#TotPeRoView Answer on Stackoverflow
Solution 6 - C#Mike ChamberlainView Answer on Stackoverflow
Solution 7 - C#Mayer SpitzView Answer on Stackoverflow
Solution 8 - C#HedegoView Answer on Stackoverflow
Solution 9 - C#Guillermo VariniView Answer on Stackoverflow
Solution 10 - C#Sahin OzsoyView Answer on Stackoverflow
Solution 11 - C#Greg F.View Answer on Stackoverflow