Unable to cast object of type 'System.Web.HttpApplication' to type 'Microsoft.Practices.CompositeWeb.WebClientApplication'

Topics: Web Client Software Factory
Dec 2, 2008 at 8:10 PM
Converted from Website to Web Application and Deployed to DEV environment - Result Pass. I followed WCSF WAP template for creating Web Application.
Once I migrated to TEST environment using XCOPY, I am getting this exception "Unable to cast object of type 'System.Web.HttpApplication' to type 'Microsoft.Practices.CompositeWeb.WebClientApplication'. "

Tasks performed so far,
1) Take TEST environment application which I migrated recently to DEV environment and run application...Result Pass..Application is working on DEV environment but not working on TEST environment
2) Check each assemblies used by application for missing dependency.....Result Pass. Both are having matching dependency.
3) Check assemblies used inside GAC with specific version....Result Pass. All assemblies are identical in both environment
4) Check web.config used in both environment...Result Pass. config is having identical signature for assemblies references and config attributes
5) Check WCSF discussion for similar exception description...Not finding suitable references.

Please help to fix this issue

Nilesh Trivedi
Dec 3, 2008 at 4:56 PM
Please post the exception details.
Dec 3, 2008 at 5:43 PM

Somehow, I fixed this issue right now by deleting PreCompiledApp.config file which was existing in Test Environment.
I still doubt that changes in web.config is not refreshing app pool on Test environment. Due to limited access to Test environment, I am not able to regenerate same issue.
I have more control on DEVenvironment where I am not able to regenerate same issue.

Reason for deleting PreCompiledApp.config
Web Application deployment does not requires PreCompiledApp.config in root folder of application. Moreover, this file has to be removed from web application root directory otherwise it may display weird error like “System.InvalidCastException: Unable to cast object of type 'System.Web.HttpApplication' to type 'Microsoft.Practices.CompositeWeb.WebClientApplication'”

so publishing Web Application does not require precompiledApp.config file.

It is created by precompiled Website deployment requires PreCompiledApp.config in root folder of application

Quotes - “The PreCompiledApp.config file is used to track the deployment of an application, and the PreCompiledApp.config file informs ASP.NET 2.0 if ASP.NET 2.0 must compile any files at request time. The updatable attribute that is set to the true value applies to ASP.NET pages (.aspx files) and to user controls (.ascx files). If we don't need to update these files, we can delete it from website.”
Link: http://forums.asp.net/t/1312410.aspx

Can anyone help me to regenerate same issue? I need to get to the bottom of this issue for justification for my next migration in end of this month. And more over Production is due in early next month...

Nilesh Trivedi

Dec 3, 2008 at 6:19 PM

Hi Nilesh,

Perhaps, you may find useful this thread that deals with the same exception:

·         System.InvalidCastException: Unable to cast object of type 'System.Web.HttpApplication' to type 'Microsoft.Practices.CompositeWeb.WebClientApplication'


Ezequiel Sculli


Jul 22, 2010 at 12:18 PM

I'have same problems. When i create precompiled version of the web, i receive [InvalidCastException: Unable to cast object of type 'System.Web.HttpApplication' to type 'Microsoft.Practices.CompositeWeb.WebClientApplication'.]. Otherwise if i work in Visual Studio 2010, all works perfectly. Is very strange.

Nov 26, 2010 at 8:39 PM
Edited Nov 26, 2010 at 8:39 PM


I answered you in other forum thread, so I think that you can find the following forum thread interesting:

If you continue experiencing this, could you please share a repro sample?

Fernando Antivero