title: ServiceStack deploy IIS 8.5 - Getting The type initializer for 'ServiceStack.HttpHandlerFactory' threw an exception
body: <p>I'm trying to deploy simple test ServiceStack (version 4.0.30) app to Windows Server 2012 on IIS 8.5.  The version of .NET is 4.5.  The app pool is set to .NET 4.0, Integrated mode.  In IIS I created a new website and mapped it to physical folder.  The folder contains web.config, and all the dlls are then in bin folder under that.</p>
  
  <p>I can run project successfully from Visual Studio 2013, but after deploy, I am getting these error messages below.  I've looked for other similar errors but don't seem to see anything quite the same.</p>
  
  <p>Here is exception stack trace: </p>
  
  <pre><code>[NullReferenceException: Object reference not set to an instance of an object.]
     ServiceStack.HttpHandlerFactory..cctor() +363
  
  [TypeInitializationException: The type initializer for 'ServiceStack.HttpHandlerFactory' threw an exception.]
     ServiceStack.HttpHandlerFactory..ctor() +0
  
  [TargetInvocationException: Exception has been thrown by the target of an invocation.]
     System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean&amp; canBeCached, RuntimeMethodHandleInternal&amp; ctor, Boolean&amp; bNeedSecurityCheck) +0
     System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark&amp; stackMark) +159
     System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark&amp; stackMark) +256
     System.Activator.CreateInstance(Type type, Boolean nonPublic) +127
     System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark&amp; stackMark) +14407909
     System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) +198
     System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture) +28
     System.Web.HttpRuntime.CreateNonPublicInstance(Type type, Object[] args) +83
     System.Web.Configuration.HandlerFactoryCache..ctor(String type) +57
     System.Web.HttpApplication.GetFactory(String type) +94
     System.Web.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +375
     System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously) +288
  </code></pre>
  
  <p>The config file looks like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;configuration&gt;
    &lt;!-- ServiceStack: CustomPath /api --&gt;
    &lt;location path="api"&gt;
      &lt;system.web&gt;
        &lt;httpHandlers&gt;
          &lt;add path="*" type="ServiceStack.HttpHandlerFactory, ServiceStack" verb="*" /&gt;
        &lt;/httpHandlers&gt;
      &lt;/system.web&gt;
      &lt;!-- ServiceStack: Required for IIS7 --&gt;
      &lt;system.webServer&gt;
        &lt;modules runAllManagedModulesForAllRequests="true" /&gt;
        &lt;validation validateIntegratedModeConfiguration="false" /&gt;
        &lt;handlers&gt;
          &lt;add path="*" name="ServiceStack.Factory" type="ServiceStack.HttpHandlerFactory, ServiceStack" verb="*" preCondition="integratedMode" resourceType="Unspecified" allowPathInfo="true" /&gt;
        &lt;/handlers&gt;
      &lt;/system.webServer&gt;
    &lt;/location&gt;
    &lt;!-- ServiceStack: Required for MONO --&gt;
    &lt;system.web&gt;
      &lt;httpHandlers&gt;
        &lt;add path="api*" type="ServiceStack.HttpHandlerFactory, ServiceStack" verb="*" /&gt;
      &lt;/httpHandlers&gt;
    &lt;/system.web&gt;
    &lt;system.webServer&gt;
      &lt;validation validateIntegratedModeConfiguration="false" /&gt;
          &lt;urlCompression doStaticCompression="false" /&gt;
    &lt;/system.webServer&gt;
    &lt;runtime&gt;
  
    &lt;/runtime&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>Thanks!</p>