Friday, February 11, 2011

Rectifying a missing namespace for MSBuild

Today I was working on adding some additional projects to a build and was getting the error:

Error CS0234: The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?)

Wait, what, this builds fine in visual studio…

System.Linq is part of System.Core. I did not have this directly referenced in visual studio but it built none the less.

image

I started to look at other projects in the build that used Linq but did not have any build issues and realized that they had System.Core referenced directly. So naturally I tried to go ahead and add System.Core to the project that was failing. Then I got this:

image

System.Core is automatically added by the build system. Well apparently not, so I had to add it manually. I opened the project file for my C# project in notepad and added the following to overwrite this error and get System.Core added.

image

After adding System.Core I was able to re-run the build and everything worked fine. As my co-worker Ralph would say, “it has been rectified”. hence the title of this blog post.

The cause of this issue is a project that is originally created as a .NET 4.0 project and then changed to a .NET 3.5 project. When Visual studio makes the alteration to the project file it does not handle adding System.Core into the project.