How to fix the "Unable to cast object of type" problem - Digital Tool Factory blog How to fix the "Unable to cast object of type" problem - Digital Tool Factory blog

How to fix the “Unable to cast object of type” problem

Drill Bitsphoto © 2008 Justin Gurbisz | more info (via: Wylio) The Problem – you have several asp.net web controls (.ascx files) in your website project and for no obvious reason you suddenly get the error “Unable to cast object of type ‘YourWebControlName_ascx’ to type ‘YourWebControlName_ascx’.”  You recompile and the program works, then stops working.  You recompile and it works again, then it stops working, ad infinitum, but the working times become less frequent, and eventually the site stops working at all.

The Cause – ASP.net will cache the wrong things.  In my case I converted the project from a full solution to a regular website and did not remove the compiled files (SolutionName.dll) in the bin and obj directories, which compounded the problem.

The Solution – Delete everything in in the “Temporary ASP.net Files” directory, which (on my machine) was located here C:WindowsMicrosoft.NETFrameworkv2.0.50727Temporary ASP.NET Files.  Then delete everything in obj directory, and the solution files from the bin directory.  That should fit it!

This was more of a stupid error on my part than a great mystery, but problematic nonetheless.

 

This post originally appeared on the Stronico blog – with the absorption of Stronico into Digital Tool Factory this post has been moved to the Digital Tool Factory blog

 

Written By Steve French

 

Leave a Reply

Your email address will not be published. Required fields are marked *






Copyright 2011 Digital Tool Factory. All Rights Reserved. Powered by raw technical talent. And in this case, WordPress.