Wednesday, April 9, 2014

VS2013 Type or Namespace name could not be found - Can't Find Internal Classes

In upgrading one of my projects from VS2010 to VS2012 to VS2013, i ran into a problem.

The Error:
The type or namespace name 'IService' could not be found (are you missing a using directive or an assembly reference?)

The Code:
namespace WcfTest
 // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service" in code, svc and config file together.
 [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Single)]
 public class Service : IService

More Code:

namespace WcfTest
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService" in both code and config file together.
    public interface IService

So both the Service and it's interface IService are in the same project, and as you can see from the code above, they're also in the same namespace. Although i could not get it to recognize the interface as existing while i was coding, during build it had no issue in finding it.

This problem left me without any Intellisense for any classes internal to the project, and would syntax highlight many things in the project as errors! Anything such as

using WcfTest.DataContracts;

would throw an error saying that DataContracts didn't exist in the given namespace.


I read a post about NuGet libraries having a similar problem and it was mentioned that if the NuGet libraries had a higher target framework than they'd need to upgrade their project's target framework to be equivalent or higher.

So even though my problems were internal to the project i decided to give it a try. Under the project's properties i change it's target framework from .NET Framework 4 to .NET Framework 4.5. Just like that i had my Intellisense back and it was recognizing my internal classes properly! Since i didn't have time to makesure 4.5 wouldn't have any problems in production, and in the spirit of investigation, i then changed my target framework back to .NET Framework 4, and everything was still working perfectly! :)

So the problem isn't the framework version it's at, but likely some metadata of the project that wasn't being grabbed properly. Fortunately changing framework versions fixes it!


Chirag Bhagat said...

I am having similar issue. I have a WebApp1.WebUI.WebBasePage class derived from System.Web.UI.Page.

When I try to change the base page from Page to WebBasePage, it gives me "Type or Namespace name could not be found" error in my page. I am using VS2013 trying to upgrade web app project.

Adam Cloud said...

I actually spun up another install of my OS in a Hyper-V VM on my development machine.

After installing VS2013 w/ upgrade 4, as opposed to installing the base and installing the updates sequentially, i was finally able to open my projects without having this issue any longer!

So the good news is that it has nothing to do with how the project is setup, and everything to do with how the frameworks/IDE were installed.

Good luck!