Unable to cast object of type 'ASP.type' to type 'ASP.type'. or Could not load file or assembly 'App_Web_xxxxxxxx, Version=, Culture=neutral,

Problem :-
Unable to cast object of type 'ASP.type' to type 'ASP.type'.
Could not load file or assembly 'App_Web_xxxxxxxx, Version=, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
 Solution :-
Both errors appear in ASP.NET application from time to time. There are some info about master pages, nested user controls related to this stuff. And hotfix from MS, usually. Not sure that hotifx helps, but you can try. Anyway, this error last till application automatic rebuild. So, you can just reupload/change some files of your project, and force rebuild. There are some notices that this error can occur weekly or even daily. Restart app every day is not looks good. Bad news. Avoid of master pages and user controls usage - is a bad idea. 
But immediate cause of this - incorrect automatic compiler work. So, to correct this error on production hosting, you can use precompiling.
The advantages of precompiling:

  1. You don't need to upload any source code on server. (Woo Hoo - hosting guys can't take your application)

  2. Above error not occurs, because source already compiled. (I recommend -fixednames option usage).

  3. Less delays because of recompiling.

  4. Small site size.
How to make your site precompiled (prepare for publish)? 
Let's start. First of all, locate this utility C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_compiler.exe (your path can be different because of windows directory). After that create a cmd-file with following content:
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_compiler -fixednames -p d:\projects\web1\source\ -v / d:\projects\web1\build\
Some descriptions regarding this line:
     -p  sets physical path to your web site source
     -v  sets virtual directory where you want to publish your site ( / set the root of virtual directory, 99% that you don't need to change this )
     -fixednames binaries will be given fixed names
I'm suggest that this should be used only for production hosting, because in case of frequent updates... not very comfortable to work through build.


Prev Post                    All Post                           Next Post

Posted in |


  1. Dallin Dyer Says:

    That worked perfect! thanks!

  2. Miguel Bocanegra Says:

    I always do the next solution: Close all VS Instances (kill all aspnet_wp.exe process), I just delete my project name folder of the above Directory and the Compiler needs to Recompile everything again, and voilaa !! Fixed ;):

    C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files

Post a Comment