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 4:41 PM
Hi,

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.

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

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

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

Chester
Coordinator
Oct 17, 2008 at 4: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?

Enjoy,
Michael Puleio -- patterns & practices
http://blogs.msdn.com/mpuleio
Oct 25, 2008 at 6: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.

Akhil.
Jul 22, 2010 at 11:17 AM

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 11:40 AM

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">

 

</font>
 
 

 

 

 

if (rootContainer != null)

{

context.AuthorizeRequest += delegate

{ 

 

 

 

 

 

 

IHttpContext httpContext = new HttpContext(context.Context);

HandleAuthorization(rootContainer, httpContext);

};

}

}

Nov 26, 2010 at 7:33 PM

Hi,

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

Fernando Antivero
http://blogs.southworks.net/fantivero