Solved

Cannot convert control (works fine on localhost though)

Posted on 2007-04-03
7
670 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 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

12 Experts available now in Live!

Get 1:1 Help Now