Type or namespace name could not be found.
In Visual Studio 2010 there is an aggravating little problem when referencing assemblies in our .NET 3.5 projects that are of an older .NET Framework version.
The type or namespace name 'MyNamespace' could not be found (are you missing a using directive or an assembly reference?)
For ages I had completely forgotten about this issue - I don’t know why, it just didn’t seem to come up - but the other day I got it again and thought it would be something to take note of.
The issue I have been encountering is just one of the many reasons this error seems to occur, a quick Google and you will see what I mean. In my case, the issue doesn’t seem to effect assemblies held in the GAC, only directly referenced assembly files.
Most (close to all) of the assemblies we encountered this problem with were not in our control. They were mostly product assemblies or 3rd party class libraries, so modifying the referenced assembly was out of the question.
After looking at the reference properties my colleague and I realised that the ‘Specific Version’ property was set to False and wasn’t being saved when we changed it. A quick look within the project file confirmed this, the Specific Version property wasn’t set at all. Adding the additional code (explained below) and setting a value of ‘True’ fixed the namespace issue we were having.
You need to open the project file so you can edit it’s contents manually. If you have PowerCommands installed, there is an option to edit the project file in the context menu when you click on the project within Solution Explorer. Otherwise, just open the project file in your favourite text editor like Notepad++.
In the project file, find the reference tag for the assembly causing the issue (the one containing the namespace in question.) and add the SpecificVersion tag within it.
<Reference Include="MyReference, Version=18.104.22.168, Cultu..."> <HintPath>..\..\..\MyReference.dll</HintPath> <SpecificVersion>True</SpecificVersion> </Reference>