This blog contains reflections and thoughts on my work as a software engineer

onsdag den 27. januar 2010

.NET 4.0 Framework Client Profile in VS2010 causing “The type or namespace could not be found”

…that has got to be in the top 3 of long headlines on this blog for sure…

Currently at work we’re doing some work on new projects – for the fun of it we’re trying the new Visual Studio 2010 to get experiences with primarily .NET 4.0 and WCF 4.0

Today I encountered a problem which almost by half an inch drove me totally mad. I was for some reason unable to reference one of our .NET 3.5 assemblies. I got the good ol’ "The type or namespace name (insert assembly) could not be found (are you missing a using directive or an assembly reference?)” error thrown at me. Intellisense worked, but the class in question wasn’t caught by the color-coding… It seemed rather odd. I did what most sane people do: I recompiled the .NET 3.5 assembly. I deleted it and recompiled. I did a restart of VS 2010. I did a reboot of my entire machine. I went to a meeting leaving the machine to think about the trouble it was causing me - without any improvement when I returned. Finally I checked the code into our source repository and had someone else check out the flawed source and make a build just to make certain it wasn’t just me who had a problem going… It turned out the problem was consistent across machine boundaries which probably is the only reason I still have a small glitch of sanity left.

After fiddling with various options and project settings my eyes suddenly fell on the Target Framework setting. It was set to “.Net 4.0 Beta Client Profile”… What the hey – I never heard about Client Profiles before…???  I changed the target to “.NET 4.0 Beta” instead and voila – I was able to build succesfully. Lots of hair lost on the way but problem solved.

I’m posting this to spread the word - maybe I’m not able to take full advantage of Google in situations like this (I do feel I’m able to find what I am looking for in other situations though) - in this particular case all I could find was a bunch of newbie-Q&A’s on pages related to “are you missing a using directive or an assembly reference” etc. I really hope that the VS 2010 guys could be able to provide a better errorcontext since I was lead in a complete wrong direction by the user. I had my new SolidState Disc, Visual Studio 2010, Windows 7, Osama Bin Laden, the Man on the Moon and just about everyone in the office under suspicion for doing hanky-panky with my machine because the error made absolutely no sense what so ever.

Read more about Client Profiles here – it seems like you have to explicitly reference assemblies in configuration but I haven’t dug into it so please correct me if I’m way off on that one.