I have a C# WebApp that we are doing for a client. I have two classes in the project, defined (in separate files) as such...
A general utility library:
namespace Client.WebApp {
public static class General {
public static MyDbClass GetDB() {
//<creates and returns MyDbClass here>
}
}
}
A PageBase class:
namespace Client.WebApp {
public class PageBase : System.Web.UI.Page {
protected MyDbClass dbo { get; set; }
public PageBase() {
dbo = General.GetDB();
}
}
}
When I try to compile, I get the error from the dbo = General.GetDB();
line:
The name 'General' does not exist in the current context Client.WebApp.
- I have double-checked that the namespace is spelled right in both files.
- I have tried adding the top-level namespace
Client.WebApp
as a using directive in the pagebase file. - I have tried fully qualifying the name as in
dbo = Client.WebApp.General.GetDB();
Nothing has helped and it insists that my General
class does not exist.
Funny thing is that while the build hits this error and stops, the code-editor does not see this error, and the statement does not get red-under-squiggled.
The project is targeting Framework v.4.5.2, and I am working in VS 2015.
My
. It will conflict with the built-inMy
namespace for anyone using VB that may want to use your assembly. – PlatedGeneral
class syntactically correct? – AgresticGeneral
class has no red squiggles and is not reporting any errors at build time. As far as I can see it is correct. – Acaulescentbin
andobj
folders from your project directories within the solution. (All project directories.) Then try another clean and build. – LockupPageBase
, it may be that you accidentally set the settings for theGeneral
cs file to be something other than "Compile", can you check the file properties, specifically the Build Action? – CounterintelligenceContent
. If you want to post that as an answer, I will accept it. I just assumed VS would add a new code file asCompile
. LOL Silly me! – Acaulescent