MonoDevelop: “Type ‘X’ does not contain a definition for ‘Y’ and no extension method ‘Y’ of type ‘X’ can be found”
Just a quick one here since I seem to keep getting caught out by this one as I develop more with MonoDevelop..
Problem
I am using an extension method, the code is completed fine via the “Intellisense”, correctly identifying that the method is an extension method, but when building, I get the error “Type ‘X’ does not contain a definition for ‘Y’ and no extension method ‘Y’ of type ‘X’ can be found”, and the build fails.
Solution
Dead easy – make sure you have a reference to System.Core. For some reason, some of my projects have not had this – and this is causing the problem. It is just made more difficult since the “detection of extension methods” seems to be working even if the plumbing (System.Core) is not actually in place to deal with them ;)
To add a reference, when the compiler moans, (making sure you are in the file that is not building):
- Click “Project” in the top menu bar.
- Click “Edit References”
- On the “Packages” tab, scroll to “System.Core” and whack a check mark next to it.
- Click “OK”.
Obviously, you need to be running a .NET 3.5 project for these to run – which should the default, but to double-check:
- Click “Project” in the top menu bar.
- Click “{Project Name} Options”
- Click “General” under the “Build” section
- Select “Mono / .NET 3.5” in “Runtime Version”
- Click “OK”.
Now hit “Build” (F8) and all should be well :)
Comments
Post a Comment