Blog

Why does my VS2010 project seem to forget assembly references at build time?

By: Alejandro Villarreal

I recently experienced one of the most puzzling issues I’ve dealt with: after I finished coding my project in Visual Studio 2010 I tried to build it but it failed, complaining of namespaces that didn’t exist (which means a bunch of types that weren’t declared and thus code that the compiler didn’t understand). This didn’t make sense because the assembly that contained those namespaces was still in the “References” part of my project, and I had used IntelliSense with the types it contained. So I knew for a fact that Visual Studio did know that the assembly was there, and was able to analyze it and use it.

But then why couldn’t I build my project? I tried removing and re-adding the reference, which fixed the “syntax errors” detected by the compiler when it lost memory of the namespaces in the external assembly, but trying to build it again caused VS to forget about them one more time.

So I turned to the Internet for a solution to this issue, and I quickly found the answer: my project was set to target the .NET Framework 4 Client Profile. First of all, what’s that? Well, MSDN says: “The .NET Framework 4 Client Profile is a subset of the .NET Framework 4 that is optimized for client applications”. Furthermore, a note in the same article states

If you are targeting the .NET Framework 4 Client Profile, you cannot reference an assembly that is not in the .NET Framework 4 Client Profile. Instead you must target the .NET Framework 4.

That explains the whole thing, and the solution is indeed as simple as changing that property of the project from one value to the other, which can be done as follows:

1.       Right click on your project in Visual Studio, and click on Properties:

 
2.       In the “Application” tab, change the value of “Target Framework” from .NET Framework 4 Client Profile to .NET Framework 4.
 
 

I’m not sure if the Client Profile should be default for new projects, or for what types of projects is it the default, but at least the problems that it might cause are easily identifiable, and the solution for them is simple.

 

Comments

Leave a comment

 
 
 
 
CAPTCHA Image Validation