Wednesday, March 28, 2012

Strange compilation errors

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?

Thanksyou 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)

"Argirop" <Argirop@.discussions.microsoft.comwrote in message
news:8B674FC6-4D83-4D02-8076-1EA6D72E804E@.microsoft.com...

Quote:

Originally Posted by

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
>
>


And how can I add a reference to Default1 in Default2 ?

"bruce barker (sqlwork.com)" wrote:

Quote:

Originally Posted by

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)
>
"Argirop" <Argirop@.discussions.microsoft.comwrote in message
news:8B674FC6-4D83-4D02-8076-1EA6D72E804E@.microsoft.com...

Quote:

Originally Posted by

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


>
>
>


Never mind, I found it.

Thanks a lot.

"Argirop" wrote:

Quote:

Originally Posted by

And how can I add a reference to Default1 in Default2 ?
>
"bruce barker (sqlwork.com)" wrote:
>

Quote:

Originally Posted by

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)

"Argirop" <Argirop@.discussions.microsoft.comwrote in message
news:8B674FC6-4D83-4D02-8076-1EA6D72E804E@.microsoft.com...

Quote:

Originally Posted by

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
>
>


0 comments:

Post a Comment