Hi,
I have a problem using an aspx page with a Control on it. I get the
following error message
Compiler Error Message: CS1595: 'Test.Class2' is defined in multiple
places; using definition from
'c:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Temp orary ASP.NET
Files\root\1f575646\ad3a161b\assembly\dl2\57ca505e \044565c0_f84fc401\Test1.DLL'
The problem is that the control is defined in two different assemblies
(with different names) but with the same namespace.
I really need this in my setup so I wonder why it doesn't work.
The thing is that it does work if i Create the Control in the code
behind instead of the aspx file.
My real question is why the heck does the runtime compiler ignores the
Assembly attribute that is specified in the Register directive? It
seems that the runtime code generator only looks at the namespace
attribute and ignores the Assembly that is specified... (or what it is
else for?)
<%@ Register TagPrefix="Test" namespace="Test" Assembly="Test1"%>
Is it possible to get rid of the /warnaserror flag that is passed to
the csc.exe when the dynamic dll is compiled?
To reproduce the behaviour:
Create a asp.net project with a webform. (WebForm1.aspx)
Create a Class Library project (Test1) and add the following class
file.
################################################## ########################
Class1.cs
################################################## ########################
using System;
namespace Test {
public class Class1 {
}
}
################################################## ########################
Create a Class Library project (Test2) and add the same class file as
above.
Add the Test1 and Test2 projects as references to the asp.net project.
Modify the WebForm1.cs file and add an instance field to the class of
Type Class1
################################################## ########################
WebForm1.cs
################################################## ########################
using System.Web.UI;
using Test;
namespace localhost {
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page {
Class1 Class1 = new Class1();
}
}
################################################## ########################
Compile. You will get a warning that the Class1 is found in multiple
places, but the compiler will choose one and go on and create the
output.
Step 2:
Create a webcontrol and add it to projects Test1 and Test2
################################################## ########################
Class2.cs
################################################## ########################
using System;
using System.Web.UI;
namespace Test {
public class Class2 : Control {
protected override void Render(HtmlTextWriter writer) {
writer.Write("Class2");
}
}
}
################################################## ########################
Modify the Webform1.aspx to add an instance of the Class2 to the page.
################################################## ########################
WebForm1.aspx
################################################## ########################
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
AutoEventWireup="false" Inherits="localhost.WebForm1" %>
<%@ Register TagPrefix="Test" namespace="Test" Assembly="Test1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
</HEAD>
<body>
<form id="WebForm1" method="post" runat="server">
<Test:Class2 id="Class2" runat="server"/>
</form>
</body>
</HTML>
################################################## ########################
Recompile and go to WebForm1.aspx in your browser.
You will get an Error message like the one below
Compiler Error Message: CS1595: 'Test.Class2' is defined in multiple
places; using definition from
'c:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Temp orary ASP.NET
Files\root\1f575646\ad3a161b\assembly\dl2\57ca505e \044565c0_f84fc401\Test1.DLL'
To try the thing that works,
Modify the Webform to
################################################## ########################
WebForm1.cs
################################################## ########################
using System.Web.UI;
using Test;
namespace localhost {
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page {
Class1 Class1 = new Class1();
protected override void CreateChildControls() {
base.CreateChildControls ();
Class2 c = new Class2();
c.ID="class2";
Controls.Add(c);
}
}
}
################################################## ########################
and
################################################## ########################
WebForm1.aspx
################################################## ########################
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
AutoEventWireup="false" Inherits="localhost.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
</HEAD>
<body>
<form id="WebForm1" method="post" runat="server">
</form>
</body>
</HTML>
################################################## ########################
Now you will get another compile warning but it will compile...
Best Regards
/Dan