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

标签 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.

最佳答案

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

tl;博士;

解决问题添加-DependencyVersion Highestinstall-package Visual Studio 中的包管理控制台中的命令。完整命令如下:

Install-Package ServiceStack -Version 3.9.71 -DependencyVersion Highest

详细解答

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

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

但是,包开发人员作为包开发人员,包的一些“补丁版本”确实引入了破坏性更改,因此在不同时间安装包的不同开发人员会获得不同的包集。

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 版本被全面引入。

关于asp.net - 启动 ServiceStack 时无法加载类型 'ServiceStack.ServiceHost.IService',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22016374/

相关文章:

c# - 自定义错误在本地工作,而不是在 IIS 上部署后

c# - 使用 ASP.Net C#、DropDownList 和重定向?

javascript - 给定轴上的所有系列必须具有相同的数据类型 - 在图表上显示数据时间时出现错误消息

c# - Web Api/ASP.NET Windows 身份验证如何工作?

c# - ServiceStack.OrmLite - 我可以做类似 Db.Select<Foo, Bar>() 的事情吗?

xamarin.ios - ServiceStack Monotouch iPhone/发布版本失败

c# - ServiceStack,Action 可以返回 `IEnumerable<IWhateverInterface>` 吗?

android - MonoTouch/MonoDroid 服务层不兼容?

ServiceStack BSD 版本 3.9.71 和 protobuf-net 版本