473,396 Members | 1,722 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,396 software developers and data experts.

LoadControl and "Unable to Cast"?

I have some simple code that loads a control with LoadControl and casts it
to the codebehind object:

Control ctrl = LoadControl("~/Controls/BlogEntryViewer.ascx");
BlogEntryViewer entry = (BlogEntryViewer)ctrl;

About 80% of the time this fails in the cast. The BlogEntryViewer.ascx file
specifies the right file (and it compiles btw):

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="BlogEntryViewer.ascx.cs"
Inherits="BlogEntryViewer" %>

About 10% of the time I get a "cannot load ASPNET_XXXXX assembly" message.
I am totally confused. THis is a converted Beta 2->RC project so it might
be about that, not sure.

Anyone have any idea? I am ripping out my hair.

Thanks,
Shawn Wildermuth
Speaker, Author and C# MVP
Nov 19 '05 #1
1 2172
It looks like changing a build setting "Use fixed naming and single page
assemblies" to unchecked (on the MSBuild Options) project property page fixes
it.

Thanks,
Shawn Wildermuth
Speaker, Author and C# MVP
I have some simple code that loads a control with LoadControl and
casts it to the codebehind object:

Control ctrl = LoadControl("~/Controls/BlogEntryViewer.ascx");
BlogEntryViewer entry = (BlogEntryViewer)ctrl;
About 80% of the time this fails in the cast. The
BlogEntryViewer.ascx file specifies the right file (and it compiles
btw):

<%@ Control Language="C#" AutoEventWireup="true"
CodeFile="BlogEntryViewer.ascx.cs" Inherits="BlogEntryViewer" %>

About 10% of the time I get a "cannot load ASPNET_XXXXX assembly"
message.
I am totally confused. THis is a converted Beta 2->RC project so it
might
be about that, not sure.
Anyone have any idea? I am ripping out my hair.

Thanks,
Shawn Wildermuth
Speaker, Author and C# MVP

Nov 19 '05 #2

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

Similar topics

0
by: Pankaj Jain | last post by:
Hi All, I have a class A which is derived from ServicesComponent to participate in automatic transaction with falg Transaction.Required. Class A is exposed to client through remoting on Http...
10
by: LaEisem | last post by:
On-the-job, I have "inherited" a lot of old C language software. A question or two about when "casting" of null pointer constants is needed has occurred during behind-the-scenes cleanup of some...
0
by: maxim mat | last post by:
Hi I need to build client for web service. But when I'm using Visual Studio .NET to add Web Reference, I get error: "Custom tool error: Unable to import WebService/Schema. Unable to import...
0
by: Amil | last post by:
I've upgrade to VS 2005. I have several pages that dynamically load user controls; I get an exception like: "Unable to cast object of type 'ASP.xxxxx' to type" I've investigated and found...
4
by: JackBlack | last post by:
Hi, all! Need a little help tracking down a runtime error problem. I'm getting this error: "Unable to cast object of type 'myStruct' to type 'myStruct'... but the two types are identical! I...
17
by: arindam.mukerjee | last post by:
I was running code like: #include <stdio.h> int main() { printf("%f\n", 9/5); return 0; }
10
by: R2d2Rabeau | last post by:
Hi, I'm new to C#, please be patient :-) I am trying to pass an Arraylist (myAL) to a jagged array (myAL2) . The problem I have is that when I write the values to a file i do not get the values...
4
by: archu007 | last post by:
hi i'm using the following statement in my application string strTArray = new string; strTArray = (string)(Session); when i run the application its giving the below error {"Unable to cast...
2
by: anj2k5 | last post by:
I uploaded music file in SQl DB in a image dataype .But when i try to reterive it,It doesn't play. It gives the following type casting error on runtime "Unable to cast object of type...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.