Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

strange warning about ExtensionAttribute

I'm getting a strange warning:

The predefined type 'System.Runtime.CompilerServices.ExtensionAttribute' is defined in multiple assemblies in the global alias; using definition from 'c:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Core.dll'

There is no line number given, so it's hard to figure out what it's on about.

The compiler error code is CS1685

like image 374
JoelFan Avatar asked Feb 13 '09 17:02

JoelFan


4 Answers

Are you using someone's dll (or your own) which had implemented this attribute (with exactly the same name) itself as a means of using some c# 3.0 features on pre .Net 3.5 runtimes? (A common trick)

This is the probable cause. Since it is using the correct one (the MS one in the GAC) this is not a problem though you should hunt down the other and remove it.

like image 193
ShuggyCoUk Avatar answered Sep 23 '22 20:09

ShuggyCoUk


Expanding on ShuggyCoUk's (correct) answer

Truthfully it doesn't matter which version of the attribute is used (GAC, 3rd part, etc ...). All that matters is the C#/VB compiler can find some attribute with the correct name. The attribute serves no functional purpose in code. It exists purely to tell the Compiler "hey, this is an extension method".

You can safely ignore this warning.

like image 20
JaredPar Avatar answered Sep 23 '22 20:09

JaredPar


I agree with ShuggyCoUk that the best course of action is to try to remove the offending dll. That may not be possible, though.

Another way to resolve the ambiguity that the compiler is complaining about is to change the Alias of the referenced dll. In your project, in the References folder, if you click on a referenced dll you will see the Aliases property. By default, this is "global", which allows you to do things like "global::SomeNamespace.SomeType". You might simply be able to change the alias to something else.

This fixed a problem I had where I needed to reference Microsoft.Scripting.Core.dll, but it contained some types that conflicted with mscorlib.dll. I changed the Aliases property to be "ThirdParty" instead of "global", and that fixed the warning.

like image 11
Ron Avatar answered Sep 21 '22 20:09

Ron


I have the same problem.

In my case the problem was the assembly Mono.Cecil.

Migrating from local references to nuget, when i add NHibernate references the package automatically adds this reference.

This reference was removed, and compiled my project again.

Remove it and be happy!!

This image was taken from ILSpy ( http://i.stack.imgur.com/Qyd5o.png )

like image 1
Luiz Carlos Faria Avatar answered Sep 20 '22 20:09

Luiz Carlos Faria