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 compile
Just target your VS project to .NET framework 3.5 and above. Most probably you converted your project from a previous version.
Try: Project, Add Reference, find System Core 3.5.0.0 in the list, and OK to add it.
Extensions are introduced in C# 3.0, which on the other hand was introduced in .NET 3.5 so you can't really use them in .NET 3.0 directly.
What version of .NET are you targetting? The ExtensionAttribute class is shipped in System.Core.dll (.NET 3.5), but you can re-declare it yourself if you want to use extension methods in .NET 2.0/3.0 (with C# 3.0, obviously). In fact, LINQBridge does this.
[update] However, I'm slightly confused, because the error you should see is:
Error 1 Cannot define a new extension method because the compiler required type 'System.Runtime.CompilerServices.ExtensionAttribute' cannot be found. Are you missing a reference to System.Core.dll? [snipped some path stuff]
For ongoing reference:
I have battled this exact same error message for the last two hours in the .Net 4.0 framework and finally tracked it down to a corrupted reference to the Microsoft.CSharp dll. It was such a frustratingly simple issue. I deleted the offending reference and added a "new" reference to that dll which was located at:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Microsoft.CSharp.dll
Hopefully this will save someone else the time and aggravation of tracking down a solution to this error message.
I had the same issue in a class library project that I had upgraded from VS 2008 to VS 2010 Beta 2. I hadn't added any extension methods to the project until after the upgrade, then I started seeing the same error.
Adding a class with the following code to the project solved the problem:
namespace System.Runtime.CompilerServices
{
public class ExtensionAttribute : Attribute { }
}
Found the tip on this blog: http://blog.flexforcefive.com/?p=105