2014年7月13日 星期日

[RESOLVED] Getting a "type of namespace could not be found" error message.


I've got a new website I've placed up. Very simple at this point, using just the 3 .aspx files that come with the default template when creating a Web Forms IDefault, About and Contact). I published it a few days ago. Today I made some very minor changes.
Now I'm getting the following error message when I compile it:


Error 1 The type or namespace name 'WestsideSW' could not be found (are you missing a using directive or an assembly reference?) C:\Websites\WestsideSW\Global.asax 2 

And here are the first 4 lines of code from my Global.asax file:


<%@ Application Language="C#" %>
<%@ Import Namespace="WestsideSW" %>
<%@ Import Namespace="System.Web.Optimization" %>
<%@ Import Namespace="System.Web.Routing" %>

The offending line of code is the second line.


I've got 2 main questions. First, how do I fix this problem? WestsideSW
is
the name of my project in VS 2012. It always has been since I created the project. I don't understand how removing some lines of code in the HTML of one of the .aspx files would suddenly cause the project to not be able to compile.


This leads to the second main question. Why is ASP.NET so incredible fragile that all one has to do is remove some h2 tags, and bam, now you can't compile the project anymore? Now the Global.asax file is messed up. Now, although it hasn't changed project,
solutions or anything, it suddenly doesn't have any awareness of the project it was in? Heck, I haven't even opened the Global.asax file until I got this stupid error. I love Microsoft's technology and development tools, but this sort of fragility borders
on being just plain silly.



delete Global.asax and recompile




One of the reasons you may get this error is if another code error somewhere in the application has caused an issue and can't compile, which in turn means that there is no WestsideSW namespace because no code has compiled.


Have you tried removing that import directive to see if other errors have occured? You can also tell VS not to include that in the solution and try to re-compile.


You are most likely running into an issue that happens when you have Import directives in .asax/.aspx/.ascx design surfaces. There are layers that are being handled during a publish or compile. The first layer is the code behind .cs files. Then on top of
that are the designer files being parsed. Most developers do their code in the global.asax.cs file, and if you did you would see more detailed errors. Since this is in the .asax file, you're not at that detailed level yet since you are at an outer layer of
the onion. One of the main benefits from not doing this in the designer file is you get better error information at compile time.



沒有留言:

張貼留言