Archive for December, 2007

Cassini & SerializationException: Type is not resolved for member…

December 18, 2007 LeandroDG 7 comments

I’m working on an architecture project now, and I needed to create an HttpModule which would measure the request time for pages.

So I needed to save information (the time and some other data) in the Begin_Request event and then read it in the End_Request event. I could have used Request.Context, but part of the idea of the project is this information in the current thread because it can be used both in Winforms and in Webforms.
This information is saved in the current thread using a class that implements ILogicalThreadAffinative. When I saved my information in the current thread (using CallContext.SetData()), suddenly an exception (not debuggeable) came up, which said:

System.Runtime.Serialization.SerializationException: Type is not resolved for member '{0}'.
   at Microsoft.VisualStudio.WebHost.Server.GetProcessToken()
   at Microsoft.VisualStudio.WebHost.Host.GetProcessToken()
   at Microsoft.VisualStudio.WebHost.Request.GetUserToken()
   at Microsoft.VisualStudio.WebHost.Request.GetServerVariable(String name)
   at System.Web.Security.WindowsAuthenticationModule.OnEnter(Object source, EventArgs eventArgs)
   at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

I was using Cassini server to test the application (the light-weight webserver that comes with Visual Studio .NET). I decided to test it with IIS and had absolutely no problem, worked like a charm. So I figured it was a problem with Cassini, not being able to find the assembly which contained my class at some point.

After some research I found a workaround in a post, I could make my class heritate from MarshalByRefObject and it would work perfectly. Even though this workaround makes it work perfectly in both Cassini and IIS (although I believe there is a small performance drop) , we shouldn’t have to worry about this, I always believed the idea of Cassini was to allow working with Web Applications without needing to create a Virtual directory in IIS, you shouldn’t even need to have IIS installed, and it should reproduce the exact same behavior in both servers.

Other workarounds I found included saving the assembly to the GAC, registering the bin directory in DEVPATH environment variable, but I think the one I describe is the easiest one to implement.

This bug has been reported by Paulo Morgado at Microsoft Connect, here is the link:

VN:F [1.9.11_1134]
Rating: 5.0/5 (1 vote cast)
Categories: Development Tags: , , , ,