Recently a friend of mine was asking for help with an issue where he was getting a namespace error when trying to compile his WPF application.
The type or namespace name ‘Utilities’ could not be found (are you missing a using directive or an assembly reference?)
I’ve seen this many times before, we all have, and figured he probably was just looking at the problem too long and it was just a simple case of not setting up a reference somewhere.
I got the solution and took a look, basically a WPF application with a couple libraries under the same solution. One of them was acting like it wasn’t set up as a reference, however it clearly was there! After screwing with it for much longer than I care to admit, I decided to try things that didn’t make sense, since the situation wasn’t making any sense. I decided to try switching the framework over from .NET 4 to .NET 4 Client Profile, since that is what the WPF application runs under. It broke a little further since there was one class inside the Utility project referencing System.Web that wasn’t being used in this project, so I excluded it and hit build.
Much to my surprise, it worked!
It didn’t make much sense, I’ve built WPF projects before without having to explicitly specify Client Profile on the external libraries… so I changed the project back to .Net 4 (no Client Profile) and it still compiled!
It seems like if there is anything in the project that would prevent it from being compiled under the Client Profile, it will not be referenceable within the WPF application. While this makes perfect sense, since the WPF app needs to be able to run under the Client Profile, the error message presented doesn’t really help a whole lot.
So in summary, if you have an application running under Client Profile that can’t reference a project properly, it is because it cannot work under Client Profile. Changing your referenced project to Client Profile will help you find the problematic code.