ServiceStack部署IIS 8.5 - 获取'ServiceStack.HttpHandlerFactory'的类型初始化程序引发异常

时间:2014-08-28 20:33:38

标签: servicestack

我正在尝试将简单的测试ServiceStack(版本4.0.30)应用程序部署到IIS 8.5上的Windows Server 2012。 .NET的版本是4.5。应用程序池设置为.NET 4.0,集成模式。在IIS中,我创建了一个新网站并将其映射到物理文件夹。该文件夹包含web.config,然后所有dll都在其下的bin文件夹中。

我可以从Visual Studio 2013成功运行项目,但在部署之后,我收到以下这些错误消息。我已经找到了其他类似的错误,但似乎没有看到任何相同的错误。

这是异常堆栈跟踪:

[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& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
   System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +159
   System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +256
   System.Activator.CreateInstance(Type type, Boolean nonPublic) +127
   System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& 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& completedSynchronously) +288

配置文件如下所示:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <!-- ServiceStack: CustomPath /api -->
  <location path="api">
    <system.web>
      <httpHandlers>
        <add path="*" type="ServiceStack.HttpHandlerFactory, ServiceStack" verb="*" />
      </httpHandlers>
    </system.web>
    <!-- ServiceStack: Required for IIS7 -->
    <system.webServer>
      <modules runAllManagedModulesForAllRequests="true" />
      <validation validateIntegratedModeConfiguration="false" />
      <handlers>
        <add path="*" name="ServiceStack.Factory" type="ServiceStack.HttpHandlerFactory, ServiceStack" verb="*" preCondition="integratedMode" resourceType="Unspecified" allowPathInfo="true" />
      </handlers>
    </system.webServer>
  </location>
  <!-- ServiceStack: Required for MONO -->
  <system.web>
    <httpHandlers>
      <add path="api*" type="ServiceStack.HttpHandlerFactory, ServiceStack" verb="*" />
    </httpHandlers>
  </system.web>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
        <urlCompression doStaticCompression="false" />
  </system.webServer>
  <runtime>

  </runtime>
</configuration>

谢谢!

1 个答案:

答案 0 :(得分:5)

发布回答,因为它也发生在我身上(使用ServiceStack超过一年之后!):

  

您是否在Global.asax.cs中初始化AppHost? - mythz