【问题标题】:Could not load type 'ServiceStack.ServiceHost.IService' when starting ServiceStack启动 ServiceStack 时无法加载类型“ServiceStack.ServiceHost.IService”
【发布时间】:2014-02-25 13:58:58
【问题描述】:

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

【问题讨论】:

    标签: asp.net servicestack servicestack-bsd


    【解决方案1】:

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

    tl;dr;

    要解决此问题,请将 -DependencyVersion Highest 添加到 Visual Studio 中包管理控制台的 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 (>=3.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 很高兴知道。看来我需要更新 NuGet。
    • @mythz 现在更新了 ServiceStack v3 的文档,在安装说明中包含了 -DependencyVersion 参数。
    • 即使在针对 .NET 4.5 的项目中使用 Install-Package ServiceStack -Version 3.9.71 -DependencyVersion Highest 命令,我仍然面临问题
    • 嗯,为我工作@Suhas ...你能提供包管理器控制台的输出吗?
    • 看了第四版的定价和开源版本没有进展的事实,我其实已经放弃了。虽然我个人觉得 ServiceStack 很棒,但很难说服我公司的管理层采用 ServiceStack
    【解决方案2】:

    我遇到了同样的问题,并按照 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
    

    这设法解决了问题。

    【讨论】:

      【解决方案3】:

      您的 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 命令。

      【讨论】:

      • 这不起作用,一位同事遇到了完全相同的问题。
      • @NeilTrodden 这很奇怪,我无法重现。您可以尝试使用NuGet command line tool。命令将是nuget.exe install ServiceStack -version 3.9.71。然后检查 dll 版本。
      • @Scott - 请参阅我对此的回答。我认为您运行的 NuGet 版本一定低于 2.8。
      【解决方案4】:

      删除 Servicestack.Text 引用并运行

      Install-Package ServiceStack.Text -Version 3.9.71

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

      Install-Package ServiceStack.Common -Version 3.9.71

      【讨论】:

        猜你喜欢
        • 2020-03-27
        • 1970-01-01
        • 1970-01-01
        • 2020-07-23
        • 1970-01-01
        • 1970-01-01
        • 2018-09-07
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多