Solved

Cannot convert control (works fine on localhost though)

Posted on 2007-04-03
7
674 Views
Last Modified: 2012-06-27
Hi Experts,

I'm having a problem with difference between my online environment and my localhost.

I have compiled my application and uploaded it when it worked on my localhost..Everything works, except for one thing and I cannot figure out why it doesn't work. In my eventlog it tells me the following:

Event code: 3005
Event message: An unhandled exception has occurred.
Event time: 4/4/2007 8:31:56 AM
Event time (UTC): 4/4/2007 6:31:56 AM
Event ID: 86822a16ffc04af7ae3afd8ea39b789d
Event sequence: 31
Event occurrence: 2
Event detail code: 0
 
Application information:
    Application domain: /LM/W3SVC/1994679262/Root-30-128201417561093750
    Trust level: Medium
    Application Virtual Path: /
    Application Path: D:\www\globalstate.nl\www\
    Machine name: SERVER2
 
Process information:
    Process ID: 2428
    Process name: w3wp.exe
    Account name: NT AUTHORITY\NETWORK SERVICE
 
Exception information:
    Exception type: InvalidCastException
    Exception message: Unable to cast object of type 'ASP.controls_formulieren_controlshowformulier_ascx' to type 'ControlShowFormulier'.
 
Request information:
    Request URL: http://www.globalstate.nl/arachna.aspx?id=386&lng=1 
    Request path: /arachna.aspx
    User host address: 192.168.1.64
    User:  
    Is authenticated: False
    Authentication Type:  
    Thread account name: NT AUTHORITY\NETWORK SERVICE
 
Thread information:
    Thread ID: 5
    Thread account name: NT AUTHORITY\NETWORK SERVICE
    Is impersonating: False
    Stack trace:    at ControlArticle.Page_Load(Object obj, EventArgs e)
   at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
   at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
   at System.Web.UI.Control.OnLoad(EventArgs e)
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Where "Unable to cast object of type 'ASP.controls_formulieren_controlshowformulier_ascx' to type 'ControlShowFormulier'. " is obviously the thing to look for.

In my ControlArticle.ascx.vb, I check in the Page_Load function, which control needs to be added to my page depending on a templateID.

Dim control As ControlShowFormulier = LoadControl("~/controls/formulieren/ControlShowFormulier.ascx")
placeHolderModule.Controls.Add(control)

That's all I do and it works for every other control, but this one is feeling obnoxious for some reason. Anyone got any idea why this could happen and better yet...how I could fix it?

Thanks in advance,
Regards,
Max.
0
Comment
Question by:DreamMaster
  • 4
  • 3
7 Comments
 
LVL 10

Accepted Solution

by:
jinn_hnnl earned 500 total points
ID: 18848916
Uhmn...

Make sure you have included the Register tag in the aspx file:
<%@ Register TagPrefix="Acme" TagName="Formulier" Src="~/controls/formulieren/ControlShowFormulier.ascx" %>

Beside, you can add the strong type when you load the control:
Dim control As ControlShowFormulier = LoadControl("~/controls/formulieren/ControlShowFormulier.ascx") CType(control, ControlShowFormulier)
placeHolderModule.Controls.Add(control)

The CType part CType(control, **..this has to be the control class name..**).

I have same problem in C# and I fix it by like:
ASP.controlshowformulier_ascx control = Page.LoadControl("~/controls/formulieren/ControlShowFormulier.ascx") as ASP.controlshowformulier_ascx;

May be you or some one can take as a reference

Hope this help

JINN
0
 
LVL 19

Author Comment

by:DreamMaster
ID: 18848964
Hi jinn...

Well...I have it solved in a way that doesn't make a hint of sense to me at all. I've changed from a compiled version to just using the source as I have it on my local machine. That works flawlessly.

I have the <%@ Register... tag at the ascx file (remember it was in a control)

I've seen similar things before, and it proved to be a matter of changing a small thing, allowing the site to be recompiled and suddenly it would work, this however would be with a main control. Sometimes even commenting out a line would work..then calling it (it won't work as suspected) but it works...uncommenting that line...eh voila it works again as normal.

I still have no idea why these bugs are happening, but I'm pretty sure they have nothing to do with the actual coding.

Thanks!
Regards,
Max.
0
 
LVL 19

Author Comment

by:DreamMaster
ID: 18849171
I think I should ask to get this question PAQ'ed...unless you disagree jinn.. :)

Regards,
Max.
0
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
LVL 10

Expert Comment

by:jinn_hnnl
ID: 18849743
GJ, Max,

I am pretty sure you are not the only one experiences this kind of problem. In any way that matter, if problem's caused by actual coding or not. It's nice to have some solutions to try (and ppl may add another explaination to it)

Aww, you can ask to get this question PAQ of course ^^.

Greeting,

JINNY ^^
0
 
LVL 19

Author Comment

by:DreamMaster
ID: 18849782
I can wait for a while as well. :) Like you said it's nice to see different reasons why this would happen.

Just hope I won't forget about the question though.. ;)

Regards,
Max.
0
 
LVL 19

Author Comment

by:DreamMaster
ID: 18903870
I have found that these kind of compilation issues are not so much problems with coding, however more a problem in Visual Studio / ASP.NET. Check out Scott Gu's blog about it..he recently made a post about this and other compilation problems.

http://weblogs.asp.net/scottgu/archive/2007/04/11/public-hotfix-patch-available-for-asp-net-compilation-issues.aspx

Jinn, thanks for your help, this question might be usefull for others as well, so I have PAQ'ed it now. :)

Regards,
Max.
0
 
LVL 10

Expert Comment

by:jinn_hnnl
ID: 18903921
Ohh,

I have read the blog, it is really helpful. Since I don't have this kind of problem, but I found something interesting to play with. (I might even experience it later).

Sometime I got that (after complied successfully several time), what I did was closing all the opening file (even solution file). Then reopen it and complie again. It's sounds weird but helps.

Thank for the credit, too Master Max. ^^ (I think my solution wasn't really helpful,)

JINN ^^

0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question