Thursday, March 31, 2011

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

From stackoverflow
  • 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.

  • The compiler does not know which System.Runtime.CompilerServices.ExtensionAttribute

    So it is using the defination from c:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Core.dll'

    A .dll you are using might have the same extenstion.

  • 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.

0 comments:

Post a Comment