Thursday, April 17, 2014

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

This is a short note on the error message. I googled and none of those matched exactly what I did and none of them solved my problem.

Since each development is different and many situation can raise the same error message. It is, therefore, important to describe my setups in order to be useful to my blogger readers.

First of all, I am hand coding my code for the sack of purities. It should apply well to cases where more complicated environment is used.

I created a user control with code behind: .ascx and .cs. I then use this user control in my web page: MyPage.aspx and MyPage.cs. For page derived .cs files, you will need to declare variables for controls that you used in MyPage.aspx. I can declare those variables for all the standard web controls. However, when I declared variable for my user control, the error message result. I did employed namespace for my user control and I did 'using' that namespace. However, the IIS Express wouldn't recognize my control until I explicitly declare the variable with full-namespace specification.

As with my previous post concerning IIS Express, this problem could be just the IIS Express issues. Even though, some of the Internet posts may suggest otherwise.

Wednesday, April 16, 2014

The server tag is not well formed. ASP.NET IIS Express aspx ascx

When working with ASP.NET with IIS Express, I hand coded the user control .ascx file using the code behind approach.
For the <%@ Control > tag, the CodeBehind is for the .dll file - not the .cs source file. To use the source file, you will have to use the CodeFile attribute. To use the CodeBehind attribute, you also have to put the .dll file in the \bin sub-directory - using ~\file.dll in the CodeBehind will not work as other directives tags (i.e. ASP.NET @ tags).

There is a problem with IIS Express when parsing the XML comment (i.e. ). Somehow, the IIS Express will try to look for 'runat' inside the comment area and try to interpret it as server tag. This prevents commenting out server tags when needed. By altering the text: runat (e.g. runat_), you can avoid the problem caused by this bug. This problem applies to .aspx and .ascx files.