Error: The default XML namespace of the project must be the MSBuild XML namespace

One day you get to work, your boss tells you that there is a project that he needs you to work on, you get the code from source control and open the project up in Visual Studio.NET

During project loading you get a series of crazy errors you have never seen before, ultimately ending in:

error : Unable to read the project file '.csproj'. .csproj(2,1): The default XML namespace of the project must be the MSBuild XML namespace. If the project is authored in the MSBuild 2003 format, please add xmlns="http://schemas.microsoft.com/developer/msbuild/2003" to the element. If the project has been authored in the old 1.0 or 1.2 format, please convert it to MSBuild 2003 format.

You scratch your head, with a big thought cloud overhead that reads “WTF???”

LoadError

You notice that the Silverlight project (in my case the project’s called “SilverlightInterface”) failed to load and is “unavailable” in Solution Explorer:

unavailable

So you try to “reload” it by right clicking on the (currently unavailable) project and selecting “Reload Project” from the menu, only to get an even nastier error message:

MSBuildError

Looking at the Output Window you’re faced with a never-before-seen error which states something about the The default XML namespace of the project must be the MSBuild XML namespace.

Fortunately the solution is simple:

  1. In Windows Explorer navigate to the project
  2. Right Click on the .cproj file, select Properties, and un-check the “Read Only” checkbox
  3. Open up the .cproj file in Notepad
  4. On line 2 change xmlns=”http://schemas.microsoft.com/developer/msbuild/2008″ to xmlns=”http://schemas.microsoft.com/developer/msbuild/2003″ (notice this only difference is we changed 2008 to 2003)
  5. Save your changes
  6. In Visual Studio right click on the (currently unavailable) project and select “Reload Project”
  7. The project will now load normally and you can get on with your life

Error: Could not load file or assembly System.Windows.Interactivity

Silverlight 4 and Visual Studio.NET 2010 are awesome, however if you are required to create a Silverlight 3 application and currently are using Visual Studio.NET 2010 than the default target for your Silverlight app will be version 4. You will have to go into the Properties panel for the Silverlight app and change its target to point to SL 3.

Symptoms:

While this is usually not an issue occasionally you may run into a deceiving error message. The project builds fine, you check the reference to the System.Windows.Interactivity assembly and it does exist, however when you go to view the XAML in the designer (either in VS or in Blend) you get the following error:

 


system-interactivity-error

Cause:

This is caused when your SL 3 app references any assembly that targets a newer version, for example Microsoft.Expression.Prototyping.Interactivity.dll or Microsoft.Expression.Interactions.dll that are found in Blend 4.

 

Resolution:

Removing the references to these assemblies will resolve the issue.

 

There is never only “one right way” to develop something

A great statement from Scott Guthrie in his article entitled About Technical Debates

There is never only “one right way” to develop something. As an opening interview question I sometimes ask people to sort an array of numbers in the most efficient way they can. Most people don’t do well with it.

This is usually not because they don’t know sort algorithms, but rather because they never think to ask the scenarios and requirements behind it – which is critical to understanding the most efficient way to do it. How big is the sequence of numbers? How random is the typical number sequence (is it sometimes already mostly sorted, how big is the spread of numbers, are the numbers all unique, do duplicates cluster together)? How parallel is the computer architecture? Can you allocate memory as part of the sort or must it be constant? Etc.

These are important questions to ask because the most efficient and optimal way to sort an array of numbers depends on understanding the answers

Error: This assembly may have been downloaded from the Web

If you’re like most programmers you get a LOT of stuff from the Internet, like sample projects, assembly’s (i.e. .DLL’s), etc… It seems like just about everything we do these days in software is somehow related to the Web, even if that means you are just blogging about it.

After upgrading a Silverlight project so that it can be developed on Visual Studio.NET 2010 I ran into a show-stopper error:

Could not load the assembly file:///.... .dll. This assembly may have been downloaded from the Web. If an assembly has been downloaded from the Web, it is flagged by Windows as being a Web file, even if it resides on the local computer. This may prevent it from being used in your project. You can change this designation by changing the file properties. Only unblock assemblies that you trust. See http://go.microsoft.com/fwlink/?LinkId=179545 for more information.

 

The recommended solution is to “Unblock” the content through Windows Explorer, the only problem is that I was developing this application on a machine at my work and that machine’s Security Settings prevented the “Unblock” feature from Windows Explorer (you couldn’t even see the Unblock button), I thought I was totally screwed.

frustration After banging my head on the desk a few thousand times a co-worker finally suggested that I copy the DLL’s to a Fat32 drive (like an external Thumb drive), then copy them back to the orginal location (over-writing the originals with the copy).

I then simply needed to select “View All Files” for the project in Visual Studio, expand the Bin directory, and delete all the contents (I also removed the reference to the DLL and re-added it just to be safe).

Recompiling the project was successful and I could finally get back to work, what a pain in the a—, hope this helps you fix this issue if you run into it