Thursday, March 22, 2012

Trouble with Multiple Master Pages in ASP.NET 2.0

I am writing an ASP.NET 2.0 application that uses more than one master page.
Currently, there are two pages, Freedom1.master and Freedom2.master. I have
no problems with Freedom1.master. However, I am having problems with
Freedom2.master.

The first problem is I sometimes get the following error when I build the
site.

The type 'Freedom2' exists in both
'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Tem porary ASP.NET
Files\freedomlincwebsite\ae6160cc\fecd2ea4\App_Web _ammoxc8r.dll' and
'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Tem porary ASP.NET
Files\freedomlincwebsite\ae6160cc\fecd2ea4\App_Web _fxnhzrev.dll'

The error appears for each page built using Freedom2.master.

The second problem occurs at runtime for statments like the following.

protected void Page_Load(object sender, EventArgs e)
{

Freedom2 master = (Freedom2)Master;
master.Page.Header.Title = "Freedom LINC Registration";Your code looks a bit confusing, you seem to be declaring an object called
master of type freedom2 and initialising it with the value contained in it's
self cast as a type freedom2. What are trying to do with that code?

"EagleRed@.HighFlyingBirds.com" wrote:

> I am writing an ASP.NET 2.0 application that uses more than one master page.
> Currently, there are two pages, Freedom1.master and Freedom2.master. I have
> no problems with Freedom1.master. However, I am having problems with
> Freedom2.master.
> The first problem is I sometimes get the following error when I build the
> site.
> The type 'Freedom2' exists in both
> 'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Tem porary ASP.NET
> Files\freedomlincwebsite\ae6160cc\fecd2ea4\App_Web _ammoxc8r.dll' and
> 'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Tem porary ASP.NET
> Files\freedomlincwebsite\ae6160cc\fecd2ea4\App_Web _fxnhzrev.dll'
> The error appears for each page built using Freedom2.master.
> The second problem occurs at runtime for statments like the following.
> protected void Page_Load(object sender, EventArgs e)
> {
> Freedom2 master = (Freedom2)Master;
> master.Page.Header.Title = "Freedom LINC Registration";
> .
> .
> .
> The error message states that there is a failure to cast an infinite integer
> to the type, Freedom2.
> What is going on? How do I address these issues? These problems are
> intermittent but significant.
> Any input is appreciated.
> Thank you,
> EagleRed
>
In this case I am changing the title of the page with the statement,

master.Page.Header.Title = "Freedom LINC Registration";

There are other occasions I wish to access properties on the master page
from the aspx page that uses it. For example to change the href on a link.

My problem is that I have multiple master pages, e.g. Freedom1. All inherit
from the Master class. Freedom1 derived pages work fine but I am getting
intermittent compilation or runtime errors with Freedom2.

Thanks,
EagleRed

"EagleRed@.HighFlyingBirds.com" wrote:

> I am writing an ASP.NET 2.0 application that uses more than one master page.
> Currently, there are two pages, Freedom1.master and Freedom2.master. I have
> no problems with Freedom1.master. However, I am having problems with
> Freedom2.master.
> The first problem is I sometimes get the following error when I build the
> site.
> The type 'Freedom2' exists in both
> 'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Tem porary ASP.NET
> Files\freedomlincwebsite\ae6160cc\fecd2ea4\App_Web _ammoxc8r.dll' and
> 'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Tem porary ASP.NET
> Files\freedomlincwebsite\ae6160cc\fecd2ea4\App_Web _fxnhzrev.dll'
> The error appears for each page built using Freedom2.master.
> The second problem occurs at runtime for statments like the following.
> protected void Page_Load(object sender, EventArgs e)
> {
> Freedom2 master = (Freedom2)Master;
> master.Page.Header.Title = "Freedom LINC Registration";
> .
> .
> .
> The error message states that there is a failure to cast an infinite integer
> to the type, Freedom2.
> What is going on? How do I address these issues? These problems are
> intermittent but significant.
> Any input is appreciated.
> Thank you,
> EagleRed
>
In article <31042077-F0EC-49B9-90D7-C782AEAE5187@.microsoft.com>,
"EagleRed@.HighFlyingBirds.com"
<EagleRedHighFlyingBirdscom@.discussions.microsoft.c om> writes
>I am writing an ASP.NET 2.0 application that uses more than one master page.
>Currently, there are two pages, Freedom1.master and Freedom2.master. I have
>no problems with Freedom1.master. However, I am having problems with
>Freedom2.master.
>The first problem is I sometimes get the following error when I build the
>site.
>The type 'Freedom2' exists in both
>'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Tem porary ASP.NET
>Files\freedomlincwebsite\ae6160cc\fecd2ea4\App_Web _ammoxc8r.dll' and
>'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Tem porary ASP.NET
>Files\freedomlincwebsite\ae6160cc\fecd2ea4\App_Web _fxnhzrev.dll'
>The error appears for each page built using Freedom2.master.

Try stopping the server, then deleting the files in the temporary
ASP.NET files folder. Then restart the server and try again. I have seen
this cure this problem.

>The second problem occurs at runtime for statments like the following.
> protected void Page_Load(object sender, EventArgs e)
> {
> Freedom2 master = (Freedom2)Master;
> master.Page.Header.Title = "Freedom LINC Registration";
<snip
Why are you doing it this way? Title is a standard property of the page,
even when master pages are used, so you can simply do...

Page.Header.Title = "Freedom LINC Registration";

More to the point, if you are setting the title to a fixed string, just
set it in the Page directive of the .aspx file instead of in code. As I
understand it, this gets compiled with the page, so will be a teensy
weensy bit faster too.

HTH

--
Alan Silver
(anything added below this line is nothing to do with me)
Needed or non needed code I have the same problem:

I usually cast master in order to hide or show some components / parts
of page. Anyhow why I want to cast master page is not an issue here.
The issue is why this cast may or may not fail.
My findings are that:
- I assume that in place compilation creates 2 copies of assembly,
- killing w3wp usually helps (if it doesn't delete asp.net tmp
folders/files),
- it may happens only after some compilation was made (after changes in
files, etc...).

I belive that, precompiled deployment is safer regarding this
problem...

I would like some more info about that problem.

bye,
D

0 comments:

Post a Comment