Solution: 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?

Problem

You get either of the following 2 compile-errors:

  • 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?
  • Cannot use ‘this’ modifier on first parameter of method declaration without a reference to System.Core.dll. Add a reference to System.Core.dll or remove ‘this’ modifier from the method declaration.

What’s probably the case

You defined an extension method in VS2010, but forgot, the project you’re working on has to compile to ASP.NET v. 2.0.

What you should do

Chillax – you can fix it!

Solution

Create a file in your project called ExtensionAttribute.cs (or whatever, really) and paste the following into it:

 

 

Hit F6!

References

Read here: http://www.danielmoth.com/Blog/Using-Extension-Methods-In-Fx-20-Projects.aspx.

Start the conversation