Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Cannot convert control (works fine on localhost though)

Posted on 2007-04-03
7
676 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

809 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