0
votes

I've downloaded a sample website application from internet that is built using legacy ASP.NET 2.0 WebForms. This application has a custom class named clsTest. In a code behind page Test.aspx.cs this class is declared as:

public clsTest myTest;

But when I compile app I get the following error on the above declaration: The type or namespace name 'clsTest' could not be found (are you missing a using directive or an assembly reference?)

Snapshot of code behind page Test.aspx.cs:

using System;
using System.Web.UI;
using myNameSpace;

namespace myNameSpace
{
    public partial class Test : Page
    {
        public int TotalMethods;

        public bool bVal;

        public clsTest myTest;

        protected void Page_Load(object sender, EventArgs e)
        {
          ....
        }
      ....
      ....
    }
}

Question: Even if I declare using myNameSpace; on top of the code behind page where the clsTest is declared, I'm still getting the above error. Why? Following is a snapshot of the clsTest class:

namespace myNameSpace
{
    public class clsTest
    {
        public bool Errors;

        public string FirstName;
        public bool FirstNameErr;

        public string LastName;
        public bool LastNameErr;
     }
}

UPDATE

Following is a screen capture of the actual legacy ASP.NET website project that I downloaded from the internet. In this actual app, the class in question is CCProcessor. As you can see in the screenshot below, CCProcessor.cs file is in the root folder of the project and I'm declaring the using ... statement at the top, yet the tooltip in the screenshot is still complaining about missing directive or an assembly. Why? Same error for another class PaymentSettings that is also present in the root folder of the project. NOTE: To see the picture clearly you may want to click on it to see in the entire browser.

enter image description here

2
Have you tried putting the class definition in the same .cs files as the Test class? - Rob Gray
You have named your class as cslTest but referencing it as clsTest - Praveen Reddy
@CodingDawg I've corrected the typo. But the problem persists. - nam
@nam Did my answer fix your problem? - Praveen Reddy
@CodingDawg Do you happen to know how to find out if the clsTest is in a different assembly or project? This probably is the case but I can't find out the assembly the class would be in? Since it's a legacy ASP.NET website project it does not have Reference folder either where I could have searched the assembly. And there is no other project inside the Visual Studio Solution. - nam

2 Answers

0
votes

I think you might be having the clsTest class in a different project or assembly and might not be referencing correctly in your web project.

Try to have the clsTest class in the same file and it should work.

using System;
using System.Web.UI;
using myNameSpace;

namespace myNameSpace
{
    public partial class Test : Page
    {
          public int TotalMethods;

          public bool bVal;

         public clsTest myTest;

          protected void Page_Load(object sender, EventArgs e)
         {
            ....
         }
       ....
      ....
    }

    public class clsTest
    {
        public bool Errors;

        public string FirstName;
        public bool FirstNameErr;

        public string LastName;
        public bool LastNameErr;
     }
}
0
votes

Put the class .cs file in the App_Code folder.