locked
CS0246: The type or namespace name 'Constants' could not be found

    Question

  • I'm using Visual Web Express and i'm including a c# file named Constants to access the common functionalities.

    The C# file is included in App_Code directory and when i access the c# file using the code below it shows the error:

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

    public partial class _Default : System.Web.UI.Page
    Line 20:     {
    Line 21:         Constants cons = new Constants();
    Line 22:         ArrayList fileContents = new ArrayList();
    Line 23:         string connString = "";

     

    What is the problem??? How to use the c# file in App_Code directory??

    Friday, February 24, 2006 1:57 PM

Answers

  • You must specify the namespace in your usings or explicit specify it by decleration:

    With using keyword


    using My.Namespace;
    public partial class _Default : System.Web.UI.Page
    {
        My.Namespace.Constants cons = new My.Namespace.Constants();
        ArrayList fileContents = new ArrayList();
    }

     

    Specific


    public partial class _Default : System.Web.UI.Page
    {
        My.Namespace.Constants cons = new My.Namespace.Constants();
        ArrayList fileContents = new ArrayList();
    }

     

    Friday, February 24, 2006 2:01 PM
  • Visual Studio allways puts classes in namespaces, please this is just a namespace problem or a missing reference problem. Just take a look at the error description on MSND, it can be found here.
    Saturday, February 25, 2006 10:55 AM

All replies

  • You must specify the namespace in your usings or explicit specify it by decleration:

    With using keyword


    using My.Namespace;
    public partial class _Default : System.Web.UI.Page
    {
        My.Namespace.Constants cons = new My.Namespace.Constants();
        ArrayList fileContents = new ArrayList();
    }

     

    Specific


    public partial class _Default : System.Web.UI.Page
    {
        My.Namespace.Constants cons = new My.Namespace.Constants();
        ArrayList fileContents = new ArrayList();
    }

     

    Friday, February 24, 2006 2:01 PM
  • The Visual WebDeveloper Express Edition does not generate any namespace for any file or form.If i use a common namespace called as Transaction and if i put all code inside that for all the files including the c# file inside App_Code and if i use

    using Transaction;

    namespace Transaction

    {

    public partial class _Default : System.Web.UI.Page

    {

    Constants cons = new Constants();

    Then an error showing Transaction not found.

    Tell me how to use the namespace for files inside App_Code and those files which are outside App_Code and .aspx files.???What is the actual problem which i encounter in Web Express Edition.

    Also without any namespace if i run using inbuilt Asp.Net development server it is running.Only in iis if i run using http://localhost/ it is showing the error.

     

    Willfin David.

     

    Saturday, February 25, 2006 3:21 AM
  • Visual Studio allways puts classes in namespaces, please this is just a namespace problem or a missing reference problem. Just take a look at the error description on MSND, it can be found here.
    Saturday, February 25, 2006 10:55 AM
  • For those who are interested in...

    I was encountering exactly the same problem and had to apply an unpleasantly dirty solution to evade that problem.

    Following situation:
    * IIS-Web called
    SampleWeb
    * APP_CODE
    contains the file Sample.cs
    * Subdirectory inside the root directory called SubDir1 --> this subdirectory is declared as separate "Application" inside the IIS6.0 Settings (you know, the folder icons becomes a gear wheel) 

    When I create a common WebForm-File, e.g. Test1.aspx inside the root folder of the web site and refer to the .cs-file as

    Sample MySample = new Sample();

    the pretty Test1.aspx file works like a charm - no error messages, nothing - pure beauty.

    And now the funny part of the story:
    When I conduct the same procedure (exactly the same way) INSIDE the subdirectory SubDir1 that painful error message

    CS0246: The type or namespace name 'Sample' could not be found

    I was trying around different approaches (using namespaces, adding assemblies, etc.) , but it didn't work.
    The only way I could get rid of that error was to place the file outside the SubDir1 -subdirectory (directly in the root dir).

    By the way: I cannot remove the Application-settings off the SubDir1-subdirectory due to uncountably many legacy reasons.

    I don't particularly expect a solution for that anomaly, but somehow or other it would be greatly interesting to hear any kind of suggestion.

     

    To all the anguished poor souls called C# developers.

    Tuesday, February 20, 2007 5:04 PM
  • If I am not wrong , each application needs its own App_Code folder. So maybe to copy the App_Code folder from root to your SampleWeb folder solves your problem.
    Wednesday, March 07, 2007 8:16 AM