Strange compilation errors

G

Guest

Assuming two aspx pages named Defaul1 and Default2 whith separate code behind
files. The corresponding class names are Defaul1 and Default2 respectively
and are in the same namespace (MyCompany.MyApplication.UI).

In the "Page_Load" of Page2 class I have the following code

if ( Context.Handler is Page1 )
Page1 sourcePage = (Page1)Context.Handler;

Not allways but quite often during the build, I see the following error:

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

The error message appears twise indicating the two code lines above.

There is no missing "using" because both classes are in the same namespace.
There is no missing assemply reference because both classes (pages) are in
the same web project.

The dev environment is VS 2005 and in the code behind files the classes are
declared as partial.

Any ideas what could be the problem?

Thanks
 
B

bruce barker \(sqlwork.com\)

you should not confuse namespaces with assemblies. namespace is just that, a
naming prefix. using a namespace just allows shortcuts in speciing names.
several assemblies (dlls) may use the same namespace, or one assembly may
have several namespaces. to reference a routine, you must specify the name,
but also must include the assembly containing the routine.

asp.net builds an assembly per page, so even though you use the same
namespace, you als need to add a reference to the page. a confusing facter
is that asp.net will compile serveral pages into the same dll if batching is
allowed. if you forgt the refernce and the pages end up in the same assembly
your ok. if they end up in different assemblies, then you're in trouble.

-- bruce (sqlwork.com)
 

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

Top