I downloaded the latest Mono.Cecil and now whenever I start up my project it gives me that error. It goes away if I remove and add mono.cecil. But that is a pain to do every time I open my project.
-
Is your project monodevelop? mono tools for VS? What? – Marc Gravell Dec 04 '10 at 11:48
3 Answers
This issue is a well know problem for all .NET 2.0 Projects that want to use Extension Methods internally and therefore declare their own internal System.Runtime.CompilerServices.ExtensionAttribute
to allow this.
There are various ways around this problem, if you're using .NET 3.5 or higher, simply compile Mono.Cecil with NET_3_5
or NET_4_0
defined. If you're targeting .NET 2 you might be lucky and get it to compile (it depends on some compiler internals, definitely not the csc commandline or MSBuild) out of the box. If not, the workaround would be stripping all occurences of that Attribute (including the definition) from the 2.0 Cecil assembly (using Cecil itself...).
I have already done this and it's not a big deal. However I feel your issue is a different one, so please provide a little more detail on the Mono Version and .NET version you're using/targeting.

- 35,298
- 14
- 114
- 172
-
Well my project is .net 4 and I changed mono.cecil to .net 4 in order to add a few extensions to it. Will try adding that define to it. – Will Dec 04 '10 at 11:57
-
Just noticed this warning from mono.cecil. "The predefined type 'System.Runtime.CompilerServices.ExtensionAttribute' is defined in multiple assemblies in the global alias; using definition from 'path' Mono.Cecil" – Will Dec 04 '10 at 12:01
-
2This error will disappear if you build Mono.Cecil for .NET 4 with the NET_4_0 symbol defined (can be set in project properties). See https://github.com/JohannesRudolph/cecil/blob/master/System.Runtime.CompilerServices/ExtensionAttribute.cs – Johannes Rudolph Dec 04 '10 at 12:19
I fixed this error by removing the reference to "Mono.Cecil.dl" and "Mono.Reflection.dll" from my project.
These two files come with db4o v8.0 (an object database) and don't appear to be needed for db4o to operate in its basic, non-optimized mode under Windows 7 x64 + .NET 4.0.

- 76,540
- 58
- 260
- 305
I am also facing the same problem. The error System.Runtime.CompilerServices.ExtensionAttribute..ctor
I'm using Newtonsoft.Json.Net dll(reference) in my project. I removed the reference to the file Newtonsoft.Json.Net20.dll, and the re-added it. After this my solution builds again.
Strange but true...my application builds successfully.
Error when using extension methods in C#
Thanks,