LoadControl and "Unable to Cast"?

S

Shawn Wildermuth

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# MV
 
S

Shawn Wildermuth

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top