default.aspx.cs can not see classes added in App_Code folder
-
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?)
Чесноков
-
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?)
Чесноков
-
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?)
Чесноков
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...
-
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?)
Чесноков
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
-
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
-
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
-
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
-
Hey Check this [http://msdn.microsoft.com/en-us/library/aa730880(VS.80).aspx](<a href=)[^]"> :)
himanshu
-
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...
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
Чесноков
-
actually not a good idia to remove them. but even in that case it fails
Чесноков
-
Hey Check this [http://msdn.microsoft.com/en-us/library/aa730880(VS.80).aspx](<a href=)[^]"> :)
himanshu
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??
Чесноков
-
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?)
Чесноков
it needed to change 'BuildAction' property of SomeClass.cs to 'Compile'
Чесноков