473,395 Members | 1,869 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Problem with runtime compilation of aspx files. Register Directive ignores Assembly

Dan
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
Nov 18 '05 #1
3 3327
Hi,

as I see it the only diff between two cases is that in Page Compilation
time when control declared on page and /warnaserror set you get compile
error while trying to do it on page code behind end up with warning. You
can set Page compilation settings by playing with Compilation tag
(http://msdn.microsoft.com/library/de...y/en-us/cpgenr
ef/html/gngrfcompilationsection.asp).

But I can't see way you need to declare same class name within same
namespace name. The all idea behind namespace is to let you declare same
classes name but under different contexts. Now you are trying to twist
this behavior...

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)52-8888377
*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #2
Dan
Hi Natty,

I checked the compilation tag, but to no success.

I really wonder why the runtime compliation engine adds too many dlls in the compilation string. For example:

If i remove the Test2 reference from the localhost project, all compilation warnings are removed and runtime compilation succeeds.

But if I add a copy of the Test2.dll to the bin folder of the webserver and recompiles/restarts the webserver (so the runtime compilation is redone) the error occures once more.

This I find quite erronious. Shouldn't the runtime compilation only look at the inheritance info from the aspx file
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="localhost.WebForm1" %>
<%@ Register TagPrefix="Test" namespace="Test" Assembly="Test1"%>

and see that the references needed are the localhost.WebForm1 type that is defined in the localhost.dll and look up its references (includning references that the referred dlls referes to) PLUS the Register option that defines the Assembly Test1 to include in compilation.

This is not the case though since this experiment fails...
If I look at the compilation string that generates the error message (or warning) I see that the list contains all dlls contained in the bin folder...
If I add more dlls to the bin folder, all of these are added as well....

Is there an explanation for this behaviour or is it just a easy way of getting most of the references right?

/Dan

"Natty Gur" wrote:
Hi,

as I see it the only diff between two cases is that in Page Compilation
time when control declared on page and /warnaserror set you get compile
error while trying to do it on page code behind end up with warning. You
can set Page compilation settings by playing with Compilation tag
(http://msdn.microsoft.com/library/de...y/en-us/cpgenr
ef/html/gngrfcompilationsection.asp).

But I can't see way you need to declare same class name within same
namespace name. The all idea behind namespace is to let you declare same
classes name but under different contexts. Now you are trying to twist
this behavior...

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)52-8888377
*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #3
Dan
Hi,

I might add why I need the duplicate of namespaces in the dll:s.

I am creating modules for a web content system and these are installed ontop of an existing platform.

I have a common class library for all of the modules (lets call it Core.dll) and changes in this library is made from time to time and it is not sure that the changes maintains binary compability.

If module 1 (assembly m1.dll) is shipped, I used to ship it alongside with the Core.dll. The assembly files are copied into the webservers bin folder.

If i later ship module 2 (assembly m2.dll) and include a new version of Core.dll that not is binary compatible, problems occurs for the systems that already has m1 installed.

My thought for the module shipping is that we collect the classes that is needed for each module in an separate assembly m1.core.dll and ship it with the module m1.dll.
This works remarkingly well since we keep the assembly sizes down and doesn't have to be binary compatible between the modules. All class files are linked in sourcesafe so all changes in the core library automatically gets included in the next release.

The only problem so far is the runtime compilation that seems to add all asseblies in the bin folder instead of only the referred ones (see sibling post).
This means in effect that I get duplicate definitions of some classes in m1.core.dll and m2.core.dll etc.

Is there a possible way if i make the m*.Core.dll a static library and adds it into the GAC? any toughts about that?

/Dan

"Natty Gur" wrote:
Hi,

as I see it the only diff between two cases is that in Page Compilation
time when control declared on page and /warnaserror set you get compile
error while trying to do it on page code behind end up with warning. You
can set Page compilation settings by playing with Compilation tag
(http://msdn.microsoft.com/library/de...y/en-us/cpgenr
ef/html/gngrfcompilationsection.asp).

But I can't see way you need to declare same class name within same
namespace name. The all idea behind namespace is to let you declare same
classes name but under different contexts. Now you are trying to twist
this behavior...

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)52-8888377
*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: neverstill | last post by:
hi- I have <a> tags in my DataList. For the href property, I want to do something like this: <a href='~/Default.aspx?show=Support&disp=Faq&p=<%# DataBinder.Eval(Container.DataItem, "name")%>'...
1
by: Lauchlan M | last post by:
Hi. I have an ASP.net project that works fine. I copied it to another project using the following steps: << (i) create a new VS.NET ASP.NET project.
3
by: Hamilton | last post by:
Hi there, I've seen this error appear a few times in newsgroups but unfortunately I haven't found one that actually provides a solution. I'm basically deploying a new website into an area at a...
16
by: Brad | last post by:
After compiling my asp.net project I'm receiving a "BC31011 - Access is denied" error when attempting to run or debug. The only thing that seems to resolve problem is IISReset. After a reset my...
8
by: Subra Mallampalli | last post by:
Hi, I am trying to use <runtime> section within the web.config file. However, the contents of the <runtime> section seem to be ignored. What am i missing here? Is <runtime> section not used by...
2
by: Praveen Ramesh | last post by:
Hi, Is there some kind of support for "Conditional Compilation Directives" in the aspx file? I want to enclose the Register tag as follows: #if DOTNET10 <%@ Register TagPrefix="sfwg"...
1
by: abh1508 | last post by:
Following a release of code the following problem occurs on certain asp ..net pages. This is not a problem on other testing/demo environments. IIS seems to be creating certain files twice in the...
0
by: Kirk | last post by:
I'm trying to use a Web Service to be a Remoting client of an existing ..NET 2.0 server. But I get the following error when I try to use System.Runtime.Remoting.Channels.Http in my WebService. ...
3
by: M Noreen | last post by:
I'm unable to build a web project that has a custom .NET control that I downloaded (from: http://blogs.msdn.com/dmitryr/archive/2006/03/26/561200.aspx) I'm running VS 2005, ASP.NET 2.0 on my...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.