Bizarro TypeInitializationException in System.Runtime.Remoting
June 7th, 2005

We’ve seen this exception on two occasions in three months in a production environment. I’m going to throw it up here since there are no Google hits on it so far, at least that I can find.

    Exception has been thrown by the target of an invocation. --->

    System.TypeInitializationException: The type initializer for
    "System.Runtime.Remoting.Channels.Http.HttpRemotingHandlerFactory" threw an exception. --->
    System.MissingFieldException: Field not found: ?.s_webServicesFactoryType.

       at System.Runtime.Remoting.Channels.Http.HttpRemotingHandlerFactory..cctor()

       --- End of inner exception stack trace ---

       --- End of inner exception stack trace ---

       at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly)

       at System.Activator.CreateInstance(Type type, Boolean nonPublic)

       at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr,
    Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)

       at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr,
    Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)

       at System.Web.Configuration.HandlerMapping.Create()

       at System.Web.Configuration.HandlerFactoryCache..ctor(HandlerMapping mapping)

       at System.Web.HttpApplication.GetFactory(HandlerMapping mapping)

       at System.Web.HttpApplication.MapHttpHandler(HttpContext context,
    String requestType, String path, String pathTranslated, Boolean useAppConfig)

       at System.Web.MapHandlerExecutionStep.System.Web.HttpApplication+IExecutionStep.Execute()

       at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)


This is a type initializer (.cctor) in System.Runtime.Remoting throwing up because one of the private fields cannot be found. Here’s the type in Reflector, proof that something is definitely rotten in the state of Denmark.

Reflector view of HttpRemotingHandlerFactory

The type initializer is just trying to set this field to null.

Reflector disassembly of HttpRemotingHandlerFactory type constructor

Here are some more of the details:

  • The servers were different, but running the same application. Their windows patch levels would have been the same. w3wp is set to recycle on these servers. This exception will happen constantly (thousands of times) until the recycle happens forcibly or on its own, then it goes away.

  • So, I think this is definitely a JIT or assembly loader bug related to some obscure timing issues. If I can get the native image or a full process dump while this is happening, presumably this could be tracked down.