servicestack,servicestack-bsd,Asp.net,servicestack,Servicestack Bsd" /> servicestack,servicestack-bsd,Asp.net,servicestack,Servicestack Bsd" />

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

Asp.net 无法加载类型';ServiceStack.ServiceHost.IService';启动ServiceStack时,asp.net,servicestack,servicestack-bsd,Asp.net,servicestack,Servicestack Bsd,在AppHost上调用Init()时出现上述错误 这是在一个干净的asp.NETV4.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.Interfac

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

这是在一个干净的asp.NETV4.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.
Package Manager控制台主机版本2.8.50126.400
键入“get help NuGet”以查看所有可用的NuGet命令。
PM>安装软件包ServiceStack-版本3.9.71
正在尝试解析依赖项“ServiceStack.Common”(≥ 3.0 && < 4.0)'.
正在尝试解析依赖项“ServiceStack.Text”。
正在尝试解析依赖项“ServiceStack.Redis”(≥ 3.0 && < 4.0)'.
正在尝试解析依赖项“ServiceStack.OrmLite.SqlServer”(≥ 3.0 && < 4.0)'.
正在安装“ServiceStack.Text 4.0.11”。
您正在从Service Stack下载ServiceStack.Text,其许可协议可在https://servicestack.net/terms. 检查软件包中是否有其他依赖项,这些依赖项可能随他们自己的许可协议一起提供。您对软件包和依赖项的使用构成您对其许可协议的接受。如果您不接受许可协议,请从设备中删除相关组件。
已成功安装“ServiceStack.Text 4.0.11”。
正在安装“ServiceStack.Common 3.9.11”。
已成功安装“ServiceStack.Common 3.9.11”。
正在安装“ServiceStack.Redis 3.9.11”。
已成功安装“ServiceStack.Redis 3.9.11”。
正在安装“ServiceStack.OrmLite.SqlServer 3.9.14”。
已成功安装“ServiceStack.OrmLite.SqlServer 3.9.14”。
正在安装“ServiceStack 3.9.71”。
已成功安装“ServiceStack 3.9.71”。
将“ServiceStack.Text 4.0.11”添加到falk.WebAPI。
已成功将“ServiceStack.Text 4.0.11”添加到falk.WebAPI。
将“ServiceStack.Common 3.9.11”添加到falk.WebAPI。
已成功将“ServiceStack.Common 3.9.11”添加到falk.WebAPI。
将“ServiceStack.Redis 3.9.11”添加到falk.WebAPI。
已成功将“ServiceStack.Redis 3.9.11”添加到falk.WebAPI。
将“ServiceStack.OrmLite.SqlServer 3.9.14”添加到falk.WebAPI。
已成功将“ServiceStack.OrmLite.SqlServer 3.9.14”添加到falk.WebAPI。
将“ServiceStack 3.9.71”添加到falk.WebAPI。
已成功将“ServiceStack 3.9.71”添加到falk.WebAPI。

您的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

建议:

  • 从项目中删除所有引用
  • 删除
    packages.config
  • 检查项目目标是否为.NET4.5
  • 清理项目
  • 然后重新运行NuGet命令

  • 这是NuGet 2.8版中引入的一个突破性的更改(出于良好的意图)。我怀疑@Scott运行的是NuGet的2.7版或更低版本

    tl;博士

    要解决此问题,请将
    -DependencyVersion Highest
    添加到Visual Studio中包管理控制台上的
    安装包
    命令中。完整命令的内容如下:

    Install-Package ServiceStack -Version 3.9.71 -DependencyVersion Highest
    
    详细答案

    在NuGet版本2.8的发行说明中,更改为

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

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

    NuGet的2.8版试图通过引入满足标准的最低补丁版本来解决此问题。这破坏了ServiceStack,也可能破坏了一整套其他包


    ServiceStack依赖于ServiceStack。Common(>=3.0&&我遇到了同样的问题,根据Scott在2月25日所说的,我在Package Manager控制台上使用了以下命令:

    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
    

    这成功地解决了问题。

    删除Servicestack.Text引用并运行

    安装软件包ServiceStack.Text-版本3.9.71

    同时删除ServiceStack.Common引用并运行


    Install Package ServiceStack.Common-Version 3.9.71

    这不起作用,一位同事也遇到了完全相同的问题。@NeilTrodden这很奇怪,我无法复制。您可以尝试使用。命令将是
    nuget.exe Install ServiceStack-Version 3.9.71
    。然后检查dll版本。@Scott-查看我的答案s、 我想您一定运行的是低于2.8.+1的NuGet版本。很高兴知道。我需要更新NuGet。mythz现在已经更新了ServiceStack的v3文档,在安装说明中包含了-DependencyVersion参数。即使安装包ServiceStack-3.9.71,我仍然面临这个问题-DependencyVersion是针对
    .NET 4.5
    Hm的项目的最高命令