Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. default.aspx.cs can not see classes added in App_Code folder

default.aspx.cs can not see classes added in App_Code folder

Scheduled Pinned Locked Moved ASP.NET
csharplinqdesignhelpquestion
12 Posts 4 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Chesnokov Yuriy

    In web project application just created I added some class to App_Code folder by means of Solution explorer. It resides in the same namespace as the web project one. But from default.aspx.cs I can not access that class reporting error that the object is not defined? but it is in the same namespace and should be visible as in C# projects. App_Code\SomeClass.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.IO;
    namespace SomeNameSpace
    {
    [Serializable]
    public class SomeClass
    {
    public SomeMethod { ... }
    }
    }

    default.aspx.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.IO;
    namespace SomeNameSpace
    {
    public partial class _Default : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {
    SomeClass sc = new SomeClass(); //<-- error

                }
        }
    

    }

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

    Чесноков

    K Offline
    K Offline
    K0306
    wrote on last edited by
    #3

    Try this. First Create a class in App_Code,like the below

    using System;
    using System.Data;
    using System.Configuration;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;

    /// <summary>
    /// Summary description for Class1
    /// </summary>
    public class Class1
    {
    public Class1()
    {
    //
    // TODO: Add constructor logic here
    //
    }

    public string test()
    {
        return "Test";
    }
    

    }

    and create the object for that class in default.aspx.cs, like

    Class1 cls = new Class1();

    and call the function "Test" in default.aspx.cs

    string str = cls.test();

    Regards, Karthik K...

    C 1 Reply Last reply
    0
    • C Chesnokov Yuriy

      In web project application just created I added some class to App_Code folder by means of Solution explorer. It resides in the same namespace as the web project one. But from default.aspx.cs I can not access that class reporting error that the object is not defined? but it is in the same namespace and should be visible as in C# projects. App_Code\SomeClass.cs

      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Web;
      using System.IO;
      namespace SomeNameSpace
      {
      [Serializable]
      public class SomeClass
      {
      public SomeMethod { ... }
      }
      }

      default.aspx.cs

      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Web;
      using System.IO;
      namespace SomeNameSpace
      {
      public partial class _Default : System.Web.UI.Page
      {
      protected void Page_Load(object sender, EventArgs e)
      {
      SomeClass sc = new SomeClass(); //<-- error

                  }
          }
      

      }

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

      Чесноков

      H Offline
      H Offline
      himanshu2561
      wrote on last edited by
      #4

      Chesnokov Yuriy wrote:

      but it is in the same namespace and should be visible as in C# projects.

      Yes,it will work. Check the namespace. Is it same? May be bymistake you have used different namespaces .Just check that.. :)

      himanshu

      F 1 Reply Last reply
      0
      • H himanshu2561

        Chesnokov Yuriy wrote:

        but it is in the same namespace and should be visible as in C# projects.

        Yes,it will work. Check the namespace. Is it same? May be bymistake you have used different namespaces .Just check that.. :)

        himanshu

        F Offline
        F Offline
        freshers
        wrote on last edited by
        #5

        Just Create a new ASP.Net project you ll not get any namespace. ASP.Net .cs files Namespace is not required.

        H 1 Reply Last reply
        0
        • F freshers

          Just Create a new ASP.Net project you ll not get any namespace. ASP.Net .cs files Namespace is not required.

          H Offline
          H Offline
          himanshu2561
          wrote on last edited by
          #6

          freshers wrote:

          Just Create a new ASP.Net project you ll not get any namespace.

          Yup that i know.. But still you can manually add namespace to you page

          himanshu

          F 1 Reply Last reply
          0
          • H himanshu2561

            freshers wrote:

            Just Create a new ASP.Net project you ll not get any namespace.

            Yup that i know.. But still you can manually add namespace to you page

            himanshu

            F Offline
            F Offline
            freshers
            wrote on last edited by
            #7

            May i know the Need of It

            H 1 Reply Last reply
            0
            • F freshers

              May i know the Need of It

              H Offline
              H Offline
              himanshu2561
              wrote on last edited by
              #8

              Hey Check this [http://msdn.microsoft.com/en-us/library/aa730880(VS.80).aspx](<a href=)[^]"> :)

              himanshu

              C 1 Reply Last reply
              0
              • K K0306

                Try this. First Create a class in App_Code,like the below

                using System;
                using System.Data;
                using System.Configuration;
                using System.Linq;
                using System.Web;
                using System.Web.Security;
                using System.Web.UI;
                using System.Web.UI.HtmlControls;
                using System.Web.UI.WebControls;
                using System.Web.UI.WebControls.WebParts;
                using System.Xml.Linq;

                /// <summary>
                /// Summary description for Class1
                /// </summary>
                public class Class1
                {
                public Class1()
                {
                //
                // TODO: Add constructor logic here
                //
                }

                public string test()
                {
                    return "Test";
                }
                

                }

                and create the object for that class in default.aspx.cs, like

                Class1 cls = new Class1();

                and call the function "Test" in default.aspx.cs

                string str = cls.test();

                Regards, Karthik K...

                C Offline
                C Offline
                Chesnokov Yuriy
                wrote on last edited by
                #9

                Without any contructors when you type in SomeClass inside default.aspx.cs it is absent in the list of objects available. Adding constructor does not help. Still the simple declaration of object is forbidden. It is not visible from .aspx.cs

                Чесноков

                1 Reply Last reply
                0
                • F freshers

                  Remove the Namespace from both .cs and aspx.cs .... It ll work

                  C Offline
                  C Offline
                  Chesnokov Yuriy
                  wrote on last edited by
                  #10

                  actually not a good idia to remove them. but even in that case it fails

                  Чесноков

                  1 Reply Last reply
                  0
                  • H himanshu2561

                    Hey Check this [http://msdn.microsoft.com/en-us/library/aa730880(VS.80).aspx](<a href=)[^]"> :)

                    himanshu

                    C Offline
                    C Offline
                    Chesnokov Yuriy
                    wrote on last edited by
                    #11

                    the namespaces are all the same. even if I change SomeClass.cs embedded in another namespace, that one also is not visible, even in intelligent help. I can not access SomeClass.cs object in any case??

                    Чесноков

                    1 Reply Last reply
                    0
                    • C Chesnokov Yuriy

                      In web project application just created I added some class to App_Code folder by means of Solution explorer. It resides in the same namespace as the web project one. But from default.aspx.cs I can not access that class reporting error that the object is not defined? but it is in the same namespace and should be visible as in C# projects. App_Code\SomeClass.cs

                      using System;
                      using System.Collections.Generic;
                      using System.Linq;
                      using System.Web;
                      using System.IO;
                      namespace SomeNameSpace
                      {
                      [Serializable]
                      public class SomeClass
                      {
                      public SomeMethod { ... }
                      }
                      }

                      default.aspx.cs

                      using System;
                      using System.Collections.Generic;
                      using System.Linq;
                      using System.Web;
                      using System.IO;
                      namespace SomeNameSpace
                      {
                      public partial class _Default : System.Web.UI.Page
                      {
                      protected void Page_Load(object sender, EventArgs e)
                      {
                      SomeClass sc = new SomeClass(); //<-- error

                                  }
                          }
                      

                      }

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

                      Чесноков

                      C Offline
                      C Offline
                      Chesnokov Yuriy
                      wrote on last edited by
                      #12

                      it needed to change 'BuildAction' property of SomeClass.cs to 'Compile'

                      Чесноков

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups