Solved

Cannot convert control (works fine on localhost though)

Posted on 2007-04-03
7
673 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

920 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now