ultimate victory, maximum power

b-rad’s blog

Archive for September, 2007

Web Client Software Factory - Error under Visual Studio 2005 with install of Visual Studio 2008 (orcas) Beta 2

After installing Visual Studio 2008 (Orcas) Beta 2 I received the following error when trying to run a Microsoft Web Client Software Factory (June 2007) based solution from Visual Studio 2005:

[ArgumentNullException: Value cannot be null. Parameter name: item] Microsoft.Practices.ObjectBuilder.WCSFExtensions.WCSFBuilderBase`1.TearDown(IReadWriteLocator locator, TItem item) +132 Microsoft.Practices.CompositeWeb.WebClientApplication.InnerPostRequestHandlerExecute(IHttpContext context) +152 Microsoft.Practices.CompositeWeb.WebClientApplication.Application_PostRequestHandlerExecute(Object sender, EventArgs e) +99 System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +92 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +64

I devised a pretty simple workaround for this problem so that I could keep on working.

1. Create a class that inherits from Microsoft.Practices.CompositeWeb.WebClientApplication which overrides Application_PostRequestHandlerExecute and add it to the Web site in the App_Code folder.

using System;
using System.Web;
using Microsoft.Practices.CompositeWeb.Interfaces;
using Microsoft.Practices.CompositeWeb.Utility;

public class MyWebClientApplication : Microsoft.Practices.CompositeWeb.WebClientApplication
{
public MyWebClientApplication()
{
}

protected override void Application_PostRequestHandlerExecute(object sender, EventArgs e)
{
HttpContext context = ((HttpApplication)sender).Context;
IHttpContext icontext = new Microsoft.Practices.CompositeWeb.Web.HttpContext(context);
if (icontext.Handler != null)
{
this.InnerPostRequestHandlerExecute(icontext);
}
}
}

We override Application_PostRequestHandlerExecute as it is the only virtual method in the stack trace. In this method we check for a null IHttpContext.Hander before passing it on to InnerPostRequestHandlerExecute. This check prevents the error from occurring.

2. Next we have to tell the web application to run our new version of WebClientApplication instead of the default. Go to Global.asax and change it from:

<%@ Application Language="C#" Inherits="Microsoft.Practices.CompositeWeb.WebClientApplication" %>

to

<%@ Application Language="C#" Inherits="MyWebClientApplication" %>

After that your Web Client Software Factory application should again be functional. This method in minimally intrusive so you can easily remove your changes once this issue is addressed in a future version of the factory.

2 comments