1

I have a asp.net Web Site Project that I am migrating to a Web Application Project. Most of the forms in this project are derived from a base class, but for some reason after the migration, the base class is not being found. My base class is in the following folder: App_Code/BaseClasses/BasePage.cs and is defined as follows:

//more stuff above
using System.Web;

public class BasePage : Page
{
    public BasePage()
    {
    }
    protected override void OnInit(EventArgs e)
    {
       //whatever
    }
    //some other stuff
}

And my forms are in a variety of folder and they use the base class like so:

//More stuff above
using System.Web;
                                       //Derived from base page
public partial class Reports_Uploads : BasePage
{
    //a bunch of stuff
}

Any time I try to derive from the base page I get the following error:

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

I tried wrapping both in the same namespace, but that didn't make any difference. There are not any errors on BasePage when I attempt to compile. Can anyone see why this would be happening?

Abe Miessler
  • 82,532
  • 99
  • 305
  • 486
  • Is BasePage `included` in the project or just in the folder? i.e. Do you see it in Visual Studio in the project, or did you just copy the file? Also, So are they now inside a namespace (and the same one)? – ispiro Aug 24 '15 at 23:20
  • Just to clarify - you are asking if it is actually "included" in the visual studio project correct (rather than just sitting on the file system)? If that is what you are asking then yes, it's included. That's how I know there aren't any errors when I compile. – Abe Miessler Aug 24 '15 at 23:23
  • Regarding the namespace issue - I think you might be right but I am not positive. If that's the case I will add it later, but for my current issue - wrapping both the base class and the derived class in the same namespace should fix the `'BasePage' could not be found` error i'm getting, correct? – Abe Miessler Aug 24 '15 at 23:26
  • Assuming that when you click F12 ("go to definition") on BasePage that's on the line: `public partial class Reports_Uploads : BasePage` and it shows you that class - perhaps all you need to do is clean the solution and rebuild it again. – ispiro Aug 24 '15 at 23:26
  • @yourPreviousComment - As far as I know - correct. – ispiro Aug 24 '15 at 23:27
  • @ispiro - if it can't find `BasePage` then you can't go to definition. Either way I tried cleaning, but that didn't have any effect. – Abe Miessler Aug 24 '15 at 23:30
  • Here's another idea - according to [this question's](http://stackoverflow.com/questions/4764978/the-type-or-namespace-name-could-not-be-found) answers - that error might arise from targeting the wrong .net version. – ispiro Aug 24 '15 at 23:33
  • `if it can't find BasePage then you can't go to definition` - Do you mean that you can't? But you _can_ see that file? Sounds like it _is_ a namespace issue - But you tried that - I guess I'm out of ideas. Good luck! – ispiro Aug 24 '15 at 23:37
  • have you included it in a `namespace`? – Sushil Aug 24 '15 at 23:40
  • @ispiro - found the problem, take a look at my answer if you are interested. Thanks for trying! – Abe Miessler Aug 24 '15 at 23:42

2 Answers2

2

Ok - it looks like I needed to do a "Convert to Web Application" on the entire project in order to get my base class recognized. A lot of the older instructions that I've seen say to right click on the project and click "Convert to Web Applicaiton", but that was not an option using Visual Studio 2013. I had to:

  1. Select the project I wanted to convert
  2. In the top menu items I had to select Project -> Convert to Web Application

Once I did that, it changed my App_Code folder to Old_App_Code and then the base class was recognized everywhere. I didn't need to add namespaces or anything.

Hope this helps someone!

Abe Miessler
  • 82,532
  • 99
  • 305
  • 486
  • +1. From looking around a bit, it looks like maybe the files in App_code are marked with the wrong Build Action for a web application. (Just read quickly. I might be wrong.) – ispiro Aug 24 '15 at 23:49
0

Try adding a using statement at the beginning, like the using System.Web line.

maybe try the following:

using App_Code.BaseClasses.BasePage; (NOTE: this may change depending on your file structure)
fraser jordan
  • 114
  • 1
  • 9