11

在我的 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

4 回答 4

17

这是 NuGet 2.8 版中引入的一项重大更改(出于善意)。我怀疑@Scott 正在运行 2.7 或更低版本的 NuGet。

tl;博士;

要解决此问题,请在 Visual Studio 的包管理控制台中添加-DependencyVersion Highest命令install-package。完整的命令如下:

Install-Package ServiceStack -Version 3.9.71 -DependencyVersion Highest

详细解答

在 NuGet 2.8 版的发行说明中,概述了对依赖项解析的更改。

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

但是,作为包开发者的包开发者,一些包的“补丁版本”确实引入了重大更改,因此不同的开发者在不同的时间安装包会得到不同的包集。

NuGet 2.8 版尝试通过引入满足标准的最低补丁版本来解决此问题。这会破坏 ServiceStack,并且可能还会破坏大量其他包。

ServiceStack 依赖于 ServiceStack.Common (>=3.0 && <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 版本被全面引入。

于 2014-02-27T09:15:25.450 回答
12

我遇到了同样的问题,并按照 Scott 在 02/25 上所说的进行了复习,我在 Package Manager Console 上使用了以下内容:

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

这设法解决了这个问题。

于 2014-02-27T23:57:53.090 回答
1

您的 NuGet 包安装非常不正确;这似乎很奇怪,因为我运行了 NuGet 并获得了正确的包和版本。

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

  • 服务栈 3.9.71

    服务堆栈.dll 3.9.71服务堆栈.
    服务接口.dll 3.9.71

  • ServiceStack.Common 3.9.71

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

  • 服务堆栈.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 命令。
于 2014-02-25T16:18:41.443 回答
0

删除 Servicestack.Text 引用并运行

Install-Package ServiceStack.Text -Version 3.9.71

还删除 ServiceStack.Common 引用并运行

Install-Package ServiceStack.Common -Version 3.9.71

于 2015-02-12T23:33:22.160 回答