You may receive an InvalidCastException error in a Microsoft ASP.NET-connected Web application when the following conditions are true:
You may also receive an error message that resembles the following:
- The Web application uses a master page, a user control, or pages that reference each other.
- The master page, the user control, or the pages are batch compiled into a single assembly.
- One of the batched dependencies is changed and causes a recompilation.
- A dynamic call to load a reference is made, such as a call to the LoadControl method.
Unable to cast object of type 'ASP.type' to type 'ASP.type'.
Note In this error message, type is a placeholder for one of the batch compiled types. You may also receive an error message that resembles the following:
Could not load file or assembly 'App_Web_xxxxxxxx, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.