Visual Studio 2010 suddenly can't see namespace?

My C# WinForms solution has two projects. A DLL which is the main project I'm working on, and an executable WinForms I call "Sandbox" so that I can compile/run/debug the DLL easily in one go.

I'm working in .Net 4.0 for both projects.

Everything was working fine until I added some seemingly innocent code, and a reference to System.Web in the DLL. Now my Sandbox project can't see the namespace of the DLL project. I didn't change anything which I believe should have affected this.

If I delete the project reference to the DLL from the Sandbox references and re-add it, then the red underlines all disappear and the colour coding comes back for all my classes etc; but as as soon as I try to build the solution, the whole thing falls apart again.

When I right-click the DLL project in the Sandbox's references and view in object browser, I can see the namespace and all the stuff in there.

I have a feeling this might be some sort of bug?

Is this some sort of VS2010 bug? I had this same issue a few months ago and I could only fix it at the time by making a whole new project and re-importing my files. This time, however, I have a bajillion files and will only do that as a last resort!

Edit: After panickedly going through and undoing all my changes, trying to find what caused the problems, it seems to be this line:

string url = "http://maps.google.com?q=" + HttpUtility.UrlEncode(address);

If I comment out this line, then I get no namespace errors and the project builds fine. I can't see anything wrong with this line though.


I'm ready to declare this a bug in VS2010, this has bitten way too many programmers already. The fix is easy: Project + Properties, Application tab, change Target Framework to ".NET Framework 4" instead of the Client Profile that is selected by default.

System.Web is not included in the client profile. Having this option in the first place is quite silly, the client profile is only 15% smaller than the full version of .NET 4.0. Having it selected by default is even sillier. But I digress.

UPDATE: mercifully this all got fixed in VS2012. Which no longer makes the client profile the default for a new project. And the client profile got retired completely in .NET 4.5, good riddance.


Check to make sure that both projects are using the non-client profile for their target framework (go to each project's properties to do this).


One possibility is that the target .NET Framework version of the class library is higher than that of the project. I faced this problem, and I solved it by closing visual studio, reopening visual studio, cleaning and rebuilding the solution. This worked for me. On some other posts, I have read the replies and most of users solved the problem by following this way.


Try building only the project with the Sandbox dll first independently.

Then point your executable project to the required dll and ensure copy local is set to true. in reference settings.

Tthen build the executable project.