首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >启动ServiceStack.ServiceHost.IService时无法加载“ServiceStack”类型

启动ServiceStack.ServiceHost.IService时无法加载“ServiceStack”类型
EN

Stack Overflow用户
提问于 2014-02-25 13:58:58
回答 4查看 6.1K关注 0票数 11

在我的AppHost上调用Init()时,我会得到上面的错误。

这是在一个干净的asp.net v4.5空web应用程序上,按照入门教程的要求,它有一个简单的HelloWorld服务。

我特别使用安装在以下内容中的较旧版本的ServiceStack:

代码语言:javascript
复制
Install-Package ServiceStack -Version 3.9.71

,它安装引用:

代码语言:javascript
复制
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

我得到的错误是:

代码语言:javascript
复制
[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的输出:

代码语言:javascript
复制
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.
EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2014-02-27 09:15:25

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

tl;dr;

要解决这个问题,请将-DependencyVersion Highest添加到Visual中包管理控制台的install-package命令中。命令全文如下:

代码语言:javascript
复制
Install-Package ServiceStack -Version 3.9.71 -DependencyVersion Highest

详细答案

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

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

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

版本2.8的NuGet试图通过引入符合标准的最低补丁版本来解决这个问题。这破坏了ServiceStack,而且可能也破坏了整个其他软件包。

ServiceStack依赖于ServiceStack.Common (>=3.0 && on;4.0)。

在过去(NuGet 2.7)中,这将引入ServiceStack.Common的3.9.71版本(最高可用的补丁数量),但现在它将引入3.9.11 ( 3.9主要/次要版本上的最低补丁版本)。

ServiceStack.Common v3.9.11对其依赖项完全没有版本约束,因此引入了version 4(商业许可!)其他软件包的版本,包括它自己的依赖项ServiceStack.Text。

谢天谢地,NuGet包括一个命令行开关,以恢复到原来的行为。详细情况见发布说明(链接在tl;dr;节中)。在这种特殊情况下,添加-DependencyVersion Highest将获得最高的满足约束的主要版本、次要版本和补丁版本,这意味着3.9.71版本将被全面拉入。

票数 17
EN

Stack Overflow用户

发布于 2014-02-27 23:57:53

我遇到了同样的问题,并仔细研究了Scott在02/25中说的话,我在Package控制台上使用了以下内容:

代码语言:javascript
复制
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

这解决了这个问题。

票数 12
EN

Stack Overflow用户

发布于 2014-02-25 16:18:41

您的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命令。
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22016374

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档