Reputation: 35812
This is the craziest what I've seen since a Fody plugin ruined my assembly by emitting invalid code and control flow varied random at runtime... No Fody this time.
Facts:
The error message (see the pic) lists two identical method specification
Error CS0121 The call is ambiguous between the following methods or properties: 'ComiCalc.Data.ExceptionExtensions.GetMessage2(System.Exception)' and 'ComiCalc.Data.ExceptionExtensions.GetMessage2(System.Exception)' ComiCalc.Data D:\2014Develop\.vsonline\ComiCalc\src\ComiCalc.Data\Services\UserService.cs 61
If I change both the call, both the method definition (only 2 edits in 2 places) to GetMessage2, then I got exactly the same error message just referring to the GetMessage2.
Any ideas?
and here is the single one method:
namespace ComiCalc.Data
{
using System;
using System.Data.Entity.Validation;
using PluralTouch.DataAccess;
// TODO: Move to PluralTouch
public static class ExceptionExtensions
{
public static string GetMessage2(this Exception exception)
{
var message = exception.Message;
if (exception is DbEntityValidationException)
{
message = ((DbEntityValidationException) exception).DbEntityValidationResultToString();
}
return message;
}
}
}
Upvotes: 11
Views: 59008
Reputation: 744
I encountered this error when using Shared Projects in Visual Studio. My shared project was included as a reference by project A. Project B then referenced project A. I mistakenly added the shared project to project B, leading to two instances of each of the shared files in the project. I then saw this error for a string extension method in one of the shared files where it was called from another shared file.
Upvotes: 0
Reputation: 1
In my case I just have add "path" to the code!!! hope that helps error CS0121
Upvotes: -2
Reputation: 1
I had the same issue while migrating from .NET3.1 to .NET6.0. I got my issue fixed by updating the reference package "System.Interactive" to the latest version (6.0.1 in my case) in csproj file.
Upvotes: 0
Reputation: 16115
In my case, I hit the same problem [impossible resolution conflicts between a single method and itself] because I used C# 8.0 and its shiny new features to build three projects that depend upon each other, transitively, like this:
Also, I had nullability checking enabled only for project A, and completely disabled for projects B and C.
The fix for me was to enable nullable annotations in project B (I did this without also enabling warnings).
I speculate that this fixes the problem by ensuring there weren't two completely different compiler modes (nullable annotated on/off) reprocessing the same interface definition, while building two projects (A and B), and then up putting conflicting nullability annotations on their respective outputs.
Upvotes: 0
Reputation: 2375
In my case, Resharper had created a new file named Annotations1.cs
file. I just deleted it and the problem solved. Maybe you need delete debug / release / obj and clean / rebuild solution.
Upvotes: 1
Reputation: 61
In my case I had the "publish" folder within my project folder. Removing the "publish" folder solved it for me.
Upvotes: 0
Reputation: 64
I had two exact classes created by a DB tool, because was executed 2 times with different parameters. I search by the class name and remove the newer, after that everything goes OK.
Upvotes: 0
Reputation: 8962
Got the same error because my project referenced to a dll, and at the same time had a transitive dependency to the same dll but at different file path.
Spotted it using extra logging during the build (Tools -> Options -> Build and Run ->output verbosity to Detailed or Diagnostic) by searching for dependency dll name: in Task "Csc" there were two occurrences of /reference with the dll
Fix was to point references to the same dll path
Upvotes: 1
Reputation: 990
I created a new project and moved all files except 'bin', 'references', 'obj' and boom. It works like charm..
Upvotes: 0
Reputation: 28272
Make sure you don't reference the output binary in your project references (i.e., the project references itself). This has happened to me in the past with Resharper (the addition of the output binary to the project references), so the extension method is both in the source and in the binary reference.
Upvotes: 30