473,769 Members | 4,846 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 = (BlogEntryViewe r)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="BlogE ntryViewer.ascx .cs"
Inherits="BlogE ntryViewer" %>

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 2191
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 = (BlogEntryViewe r)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="BlogE ntryViewer.ascx .cs" Inherits="BlogE ntryViewer" %>

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
7389
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 channal hosting into IIS. There is a class B which is also available through remoting hosted on IIS on the same URI. B creates new of A inside a function. It succeed and able to create instance of A inside B first time. But it failes in 2nd attempt when...
10
2620
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 of that software. That subject seems not to be addressed, at least not directly, in the C FAQ where FAQ 5.2 seems most relevant. References: * C FAQ 5.2 Null pointers (Including conditions where "casting" of null pointer...
0
2988
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 binding 'controllerSoapBinding' from namespace 'http://Bla-Bla-Bla'. Unable to import operation 'getClient'. The datatype 'Array' is missing. " Some problem when I try to use wsdl.exe tool in .NET. I get: Schema validation warning: Type 'cww:Class' is...
0
1260
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 out that this is a known issue. The recommendations I've seen indicate I should add either the Page directive "Reference Control" or "Register" to the aspx file. I checked all my files and they all have the "Reference Control" directive (I think...
4
2462
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 have a class method that's building an array of user-defined structures (see below), and returning that array to the calling routine. I'm getting the error on that calling line. The structure in both the webform and class are defined like this:
17
2516
by: arindam.mukerjee | last post by:
I was running code like: #include <stdio.h> int main() { printf("%f\n", 9/5); return 0; }
10
7559
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 instead I get "System.String" ? How can I fix the problem? I wanted to use ArralyList because its length is flexible and I can add values to it. ...All help will be greatly appreciated. Here's my code:
4
11287
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 object of type 'System.String' to type 'System.String'."}
2
10814
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 'System.Byte' to type 'System.IO.Stream'. I used the following code to play musicfile
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10212
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10047
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9995
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6674
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5304
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3962
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3563
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.