Composite Control Namespace problem

G

Guest

Hello

I am developing a composite control and I ran into the namespace problem. It boils down to the following simple example
Create a Test ASP.NET application with a Test1.aspx page. Drop an ASP.NET Label control on this page. Change the namespace of the project and of the Test1 class to the "Label". Now the project could be compiled just fine, however, when you navigate to the Test1.aspx page you'll get the following error (See below

Why does .NET framework get confused with my namespace "Label" and try to find my Test1 class in the 'System.Web.UI.WebControls.Label’
Is it possible to avoid this problem, yet keep the namespace "Label" for my project/class

Thanks
Dima Maltse

-------- Error

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0234: The type or namespace name 'Test1' does not exist in the class or namespace 'System.Web.UI.WebControls.Label' (are you missing an assembly reference?

Source Error



Line 33:
Line 34: [System.Runtime.CompilerServices.CompilerGlobalScopeAttribute()
Line 35: public class Test1_aspx : Label.Test1, System.Web.SessionState.IRequiresSessionState
Line 36:
Line 37:


Source File: c:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files\ctrltest\d8a9a48d\8cd88007\jzs16tht.0.cs Line: 35
 
B

Ben Miller [MSFT]

This is where you get into Namespace conflicts. There is a class that is
compiled from the ASP.NET Page that automatically includes
System.Web.UI.WebControls and that is where Label resides. So you just
cannot do it, unless I missed something in the namespace realm.

Here is the compiler output of the autogenerated code for the ASP.NET aspx
page.

namespace ASP {
Line 12: using System;
Line 13: using System.Collections;
Line 14: using System.Collections.Specialized;
Line 15: using System.Configuration;
Line 16: using System.Text;
Line 17: using System.Text.RegularExpressions;
Line 18: using System.Web;
Line 19: using System.Web.Caching;
Line 20: using System.Web.SessionState;
Line 21: using System.Web.Security;
Line 22: using System.Web.UI;
Line 23: using System.Web.UI.WebControls;
Line 24: using System.Web.UI.HtmlControls;
Line 25: using ASP;
Line 26:
Line 27:
Line 28:
[System.Runtime.CompilerServices.CompilerGlobalScopeAttribute()]
Line 29: public class Test1_aspx : Label.Test1,
System.Web.SessionState.IRequiresSessionState {
Line 30:

This is done automatically for the asp.net aspx page.

You will just have to use a different namespace that avoids the conflicts
from System.Web.UI.WebControls.

Corrections are welcome.

Ben Miller
--
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


Dima Maltsev said:
Hello,

I am developing a composite control and I ran into the namespace problem.
It boils down to the following simple example:
Create a Test ASP.NET application with a Test1.aspx page. Drop an ASP.NET
Label control on this page. Change the namespace of the project and of the
Test1 class to the "Label". Now the project could be compiled just fine,
however, when you navigate to the Test1.aspx page you'll get the following
error (See below)
Why does .NET framework get confused with my namespace "Label" and try to
find my Test1 class in the 'System.Web.UI.WebControls.Label'?
Is it possible to avoid this problem, yet keep the namespace "Label" for my project/class?

Thanks,
Dima Maltsev

-------- Error:

Compilation Error
Description: An error occurred during the compilation of a resource
required to service this request. Please review the following specific error
details and modify your source code appropriately.
Compiler Error Message: CS0234: The type or namespace name 'Test1' does
not exist in the class or namespace 'System.Web.UI.WebControls.Label' (are
you missing an assembly reference?)
Source Error:



Line 33:
Line 34: [System.Runtime.CompilerServices.CompilerGlobalScopeAttribute()]
Line 35: public class Test1_aspx : Label.Test1,
System.Web.SessionState.IRequiresSessionState {
Line 36:
Line 37:


Source File: c:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Temporary
ASP.NET Files\ctrltest\d8a9a48d\8cd88007\jzs16tht.0.cs Line: 35
 
J

Jeffrey Tan[MSFT]

Hi Dima,

I have viewed that this post has been posted in serveral groups.

I have added a reply to you in
microsoft.public.dotnet.framework.aspnet.webcontrols, please follow up
there, I will work with you.

Thanks for your understanding.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

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