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

Topics: Web Client Software Factory, UIP Application Block discussion, User Forum
Oct 10, 2008 at 5:41 PM

I am facing an invalid cast exception in my web client application, have tried everything mentioned in the post without any help. Stack Trace is as follows:

[InvalidCastException: Unable to cast object of type 'System.Web.HttpApplication' to type 'Microsoft.Practices.CompositeWeb.WebClientApplication'.]
   Microsoft.Practices.CompositeWeb.Authorization.WebClientAuthorizationModule.Init(HttpApplication context) +135
   System.Web.HttpApplication.InitModulesCommon() +66
   System.Web.HttpApplication.InitInternal(HttpContext context, HttpApplicationState state, MethodInfo[] handlers) +1006
   System.Web.HttpApplicationFactory.GetNormalApplicationInstance(HttpContext context) +259
   System.Web.HttpApplicationFactory.GetApplicationInstance(HttpContext context) +114
   System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +350

Have compiled all the outputs including Global.asax into 1 dll using Web Deployment Project Addin, and the methods etc. are being shown in ILDASM also, but still i am getting this error. I am getting this error only in QA environment where WCSF is not installed, which i believe need not be installed, i am including the WCSF dll as part of my setup and they are there in QA. Also, fusion log says the binding to be success.

Please help me, as i have spend almost 2 days to figure out the problem.

Oct 13, 2008 at 4:48 AM
Did you derive your Global.asax from WebClientApplication?

Oct 14, 2008 at 4:53 PM
Yes, i did.

Oct 15, 2008 at 5:22 PM
IIS ASP.NET version on QA?

Oct 17, 2008 at 5:58 PM
You are right that you do not need to install WCSF on the machine you deploy to, you just need to make sure you have all the dependencies.  WCSF is meant to be xcopy deployable.
What version of IIS are they using, and is there any chance a DLL was missed?

Michael Puleio -- patterns & practices
Oct 25, 2008 at 7:36 PM
Was able to figure out problem using reflector. There was a System.Web.Extension dll missing, couldn't figure out why missing Ajax dll is giving, Unable to cast object of type 'System.Web.HttpApplication' to type 'Microsoft.Practices.CompositeWeb.WebClientApplication'. Also, if i am deploying each page assembly then how the system was finding this dll.

Jul 22, 2010 at 12:17 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.

Jul 22, 2010 at 12:40 PM

i debug source code and exception is raise in WebClientAuthorizationModule Class



[SuppressMessage("Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods",Justification = "Validation done by Guard class.")] 

 public void Init(HttpApplication

context) { 






Guard.ArgumentNotNull(context, "httpApplication");

CompositionContainer rootContainer = ((WebClientApplication) context).RootContainer; // Thi is row with cast exception 




<font face="Consolas" size="2">






if (rootContainer != null)


context.AuthorizeRequest += delegate








IHttpContext httpContext = new HttpContext(context.Context);

HandleAuthorization(rootContainer, httpContext);




Nov 26, 2010 at 8:33 PM


I do not know you exact scenario, but I think that you can find the following blog post interesting:

Fernando Antivero