启动ServiceStack时无法加载类型'ServiceStack.ServiceHost.IService'

时间:2014-02-25 13:58:59

标签: asp.net servicestack servicestack-bsd

在AppHost上调用Init()时出现上述错误。

这是一个干净的asp.net v 4.5空Web应用程序,它带有一个简单的HelloWorld服务,按照入门教程。

我专门使用安装的旧版ServiceStack:

Install-Package ServiceStack -Version 3.9.71

安装对以下内容的引用:

ServiceStack.dll 3.9.70.0
ServiceStack.Common.dll 3.9.9.0
ServiceStack.Interfaces.dll 3.9.9.0
ServiceStack.OrmLite.dll 3.9.14.0
ServiceStack.OrmLite.SqlServer.dll 1.0.0.0
ServiceStack.Redis.dll 3.9.11.0
ServiceStack.ServiceInterface.dll 3.9.70.0
ServiceStack.Text.dll 4.0.11.0

我得到的错误是:

[TypeLoadException: Could not load type 'ServiceStack.ServiceHost.IService' from assembly 'ServiceStack.Interfaces, Version=3.9.9.0, Culture=neutral, PublicKeyToken=null'.]
   Falck.WebAPI.AppHost..ctor() in c:\inetpub\wwwroot\WebAPI\Falck.WebAPI\Global.asax.cs:17
   Falck.WebAPI.Global.Application_Start(Object sender, EventArgs e) in c:\inetpub\wwwroot\WebAPI\Falck.WebAPI\Global.asax.cs:29

[HttpException (0x80004005): Could not load type 'ServiceStack.ServiceHost.IService' from assembly 'ServiceStack.Interfaces, Version=3.9.9.0, Culture=neutral, PublicKeyToken=null'.]
   System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +9865825
   System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +118
   System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +336
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296

[HttpException (0x80004005): Could not load type 'ServiceStack.ServiceHost.IService' from assembly 'ServiceStack.Interfaces, Version=3.9.9.0, Culture=neutral, PublicKeyToken=null'.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9880168
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254

它说它无法加载类型,但我不知道为什么?

以下是nuget的输出:

Package Manager Console Host Version 2.8.50126.400

Type 'get-help NuGet' to see all available NuGet commands.

PM> Install-Package ServiceStack -Version 3.9.71
Attempting to resolve dependency 'ServiceStack.Common (≥ 3.0 && < 4.0)'.
Attempting to resolve dependency 'ServiceStack.Text'.
Attempting to resolve dependency 'ServiceStack.Redis (≥ 3.0 && < 4.0)'.
Attempting to resolve dependency 'ServiceStack.OrmLite.SqlServer (≥ 3.0 && < 4.0)'.
Installing 'ServiceStack.Text 4.0.11'.
You are downloading ServiceStack.Text from Service Stack, the license agreement to which is available at https://servicestack.net/terms. Check the package for additional dependencies, which may come with their own license agreement(s). Your use of the package and dependencies constitutes your acceptance of their license agreements. If you do not accept the license agreement(s), then delete the relevant components from your device.
Successfully installed 'ServiceStack.Text 4.0.11'.
Installing 'ServiceStack.Common 3.9.11'.
Successfully installed 'ServiceStack.Common 3.9.11'.
Installing 'ServiceStack.Redis 3.9.11'.
Successfully installed 'ServiceStack.Redis 3.9.11'.
Installing 'ServiceStack.OrmLite.SqlServer 3.9.14'.
Successfully installed 'ServiceStack.OrmLite.SqlServer 3.9.14'.
Installing 'ServiceStack 3.9.71'.
Successfully installed 'ServiceStack 3.9.71'.
Adding 'ServiceStack.Text 4.0.11' to Falck.WebAPI.
Successfully added 'ServiceStack.Text 4.0.11' to Falck.WebAPI.
Adding 'ServiceStack.Common 3.9.11' to Falck.WebAPI.
Successfully added 'ServiceStack.Common 3.9.11' to Falck.WebAPI.
Adding 'ServiceStack.Redis 3.9.11' to Falck.WebAPI.
Successfully added 'ServiceStack.Redis 3.9.11' to Falck.WebAPI.
Adding 'ServiceStack.OrmLite.SqlServer 3.9.14' to Falck.WebAPI.
Successfully added 'ServiceStack.OrmLite.SqlServer 3.9.14' to Falck.WebAPI.
Adding 'ServiceStack 3.9.71' to Falck.WebAPI.
Successfully added 'ServiceStack 3.9.71' to Falck.WebAPI.

4 个答案:

答案 0 :(得分:17)

这是NuGet 2.8版中引入的一个突破性变化(有良好的意图)。我怀疑@Scott正在运行NuGet 2.7或更低版​​本。

<强> TL;博士;

要解决此问题,请在Visual Studio的程序包管理控制台中将-DependencyVersion Highest添加到install-package命令。完整命令显示为:

Install-Package ServiceStack -Version 3.9.71 -DependencyVersion Highest

详细答案

在NuGet 2.8版的发行说明中,更改为dependency resolution is outlined

旧版本找到了满足依赖性的最低主要版本和次要版本,然后加载了最高的补丁版本。这样做的理由是修补程序版本应该用于修复错误,并且不会引入任何重大更改。

但是,软件包开发人员是软件包开发人员,软件包的某些“修补程序版本”确实引入了重大变化,因此在不同时间安装软件包的不同开发人员会得到一组不同的软件包。

NuGet 2.8版尝试通过提取满足条件的最低补丁版本来解决此问题。这打破了ServiceStack,也可能打破了许多其他软件包。

ServiceStack依赖ServiceStack.Common(&gt; = 3.0&amp;&amp;&lt; 4.0)。
在过去(NuGet 2.7),这将引入ServiceStack.Common版本3.9.71(最高可用补丁号),但现在它拉入3.9.11(3.9主要/次要版本的最低补丁版本)。

ServiceStack.Common v3.9.11根本没有对其依赖项的版本限制,因此请使用其他软件包的版本4(商业许可!)版本,包括它自己的依赖项ServiceStack.Text。

值得庆幸的是,NuGet包含一个命令行开关以恢复旧的行为。它的详细信息在发行说明中(链接到上面的tl; dr;部分)。在这种特殊情况下,添加-DependencyVersion Highest将获得满足约束条件的最高主要版本,次要版本和补丁版本,这意味着3.9.71版本将被全面引入。

答案 1 :(得分:12)

我遇到了同样的问题,经过Scott在02/25所说的话,我在软件包管理器控制台上使用了以下内容:

Install-Package ServiceStack -Version 3.9.71 -IgnoreDependencies
Install-Package ServiceStack.Common -Version 3.9.71 -IgnoreDependencies
Install-Package ServiceStack.OrmLite.SqlServer -Version 3.9.71 -IgnoreDependencies
Install-Package ServiceStack.Redis -Version 3.9.71 -IgnoreDependencies
Install-Package ServiceStack.Text -Version 3.9.71 -IgnoreDependencies

这设法解决了这个问题。

答案 2 :(得分:1)

您的NuGet包安装非常不正确;这看起来很奇怪,因为我已经运行了NuGet并获得了正确的软件包和版本。

运行Install-Package ServiceStack -Version 3.9.71应该安装以下包含以下版本的dll的包:

  • ServiceStack 3.9.71

      

    ServiceStack.dll 3.9.71
      ServiceStack.ServiceInterface.dll 3.9.71

  • ServiceStack.Common 3.9.71

      

    ServiceStack.Common.dll 3.9.71
      ServiceStack.Interfaces.dll 1.0.0

  • ServiceStack.Redis 3.9.71

      

    ServiceStack.Redis.dll 3.9.71

  • ServiceStack.OrmLite.SqlServer 3.9.71

      

    ServiceStack.OrmLite.dll 3.9.71
      ServiceStack.OrmLite.SqlServer.dll 3.9.71

  • ServiceStack.Text 3.9.71

      

    ServiceStack.Text.dll 3.9.71

建议:

  1. 删除项目中的所有引用。
  2. 删除packages.config
  3. 检查项目目标是否为.NET 4.5。
  4. 清理项目。
  5. 然后重新运行NuGet命令。

答案 3 :(得分:0)

删除Servicestack.Text引用并运行

Install-Package ServiceStack.Text -Version 3.9.71

还删除ServiceStack.Common引用并运行

Install-Package ServiceStack.Common -Version 3.9.71