Compilation error CS0103

L

Lubomir

Hi,

I have an enum definition:

namespace MyNamespaceA
{
public enum MyEnum { ...};
....
}

In another file I have a class:
namespace MyNamespaceA
{
public partial class MyClass : MasterPage
{
protected void Method()
{
MyEnum xx = ....;
}
}
}

When I build it, it is OK. Visual studio recognizes the enum type and offers
intelisense for it.
Whe I run this project in debugger (not using IIS) I get compilation error:
"An error occured during the compilation of a resource required to service
this request. ... CS0103: The name MyEnum does not exists in the current
context."

Why is that? Everything is compiled into one dll.

Thanks,
Lubomir
 
L

Lubomir

I think whats is happaning is, that when the page associated with MyClass is
loaded, the type Myenum is not loaded into the HttpContext.Current, and
therefore I get the message that Myenum doesn't exist.

How to make it "exist" ?

/Lubomir
 
B

bruce barker

the enum definition should be in its own class file (not a page
codebehind). the class shoudl be in the appcode folder.

-- bruce (sqlwork.com)
 
L

Lubomir

Yes, the enum ios in its own class file, not a code behind. Neither class nor
enum is accessible.
There is no app_code folder, as it is an ASP.NET project, not an ASP.NET web
site app.

/Lubomir
 
J

Juan T. Llibre

re:
!> There is no app_code folder, as it is an ASP.NET project, not an ASP.NET web site app.

You mean an ASP.NET Application Project, right ?
You can create the App_Code folder manually, though, and place your class file in it.

Create the App_Code folder using the "New Folder" option.

Even though the option to add it as a special ASP.NET folder isn't available in ASP.NET Application
Projects, if you create the App_Code folder manually ASP.NET will treat it as a special ASP.NET folder.

First, create the App_Code folder.
Then, use "File", "New File" and "Save as..." to save the class file in the App_Code folder.

It still won't be visible in the App_Code folder, though.

You'll need to add the file to the folder by right-clicking App_Code
and using the "Add", "Existing Item" context menu option.

All class files you place in the App_Code folder will be automatically compiled
and the functions in it will be available in code by importing its namespace.





Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
=========================
 
L

Lubomir

I created the App_Code folder and put my class into it. Now everything works
fine.

I am a bit confused however, as I have never had to do it in my previous
projects. Only difference between the project now and in the past is, that
now I am using master and nested master pages. Can that be a reason why I
have to use APP_Code folder now?

Thanks,
Lubomir
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top