I came across an issue that makes me think there is bug in the 3.0 framework. When I try to use extension methods I get the following error:
Missing compiler required member 'System.Runtime.CompilerServices.ExtensionAttribute..ctor'
When using this simple code:
public static class StringUtils { static void TestExtension(this String targetString) { } }
The only way to make this compile error go away is to add the following code:
namespace System.Runtime.CompilerServices { public class ExtensionAttribute : Attribute { } }
It’s been a few months since I have used extensions methods, but I’m pretty sure I didn’t have to do this. Has anyone else come across this issue?
I just ran into this problem myself. In my case, it was because I converted a VS 2005/.Net 2.0 project to a VS 2008/.Net 3.5 project. The conversion tool kept references to System.Core 2.0, and I couldn’t find an easy way to change the references to System.Core 3.5.
I ended up re-creating the project in VS 2008 from scratch, and it was created with proper references to System.Core 3.5