azure - 使用 F# 在 Azure 辅助角色中托管 SignalR 时出现 FileLoadException

标签 azure f# signalr owin

我正在尝试在 Windows Azure 辅助角色中运行 SignalR 自主机服务器,但不断收到

System.IO.FileLoadException: Could not load file or assembly 'Microsoft.Owin, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

当我在控制台应用程序中运行相同的代码时,它运行良好并且一切都按预期工作。整个辅助角色是用 F# 编写的。下面是产生我正在讨论的异常的最短代码:

override wr.Run() =
    let x : IAppBuilder = null

    x.MapSignalR() |> ignore // this line throws the FileLoadException

exception

当然,上面的代码不应该工作,但有不同的异常(exception)。通常我在 Startup 类 (WebApp.Start(url)) 的 Configuration() 方法中调用 MapSignalR。

我粘贴的异常详细信息来自计算模拟器,但我在实时云服务中得到了相同的信息。

您知道什么可能导致该问题或者我如何进一步诊断它吗?

最佳答案

这是 Nuget 的一个已知问题:请参阅 this 。不会为辅助角色项目自动添加绑定(bind)重定向。此失败的原因是 SignalR 二进制文件是依赖于 Microsoft.Owin 版本 2.0.0 构建的。但公共(public)源中 Microsoft.Owin 的最新可用版本是 2.0.2。要解决此程序集绑定(bind)问题,当您在控制台应用程序或 Web 应用程序上安装相同的 SignalR 包时,您将看到在 app.config 中自动添加程序集绑定(bind)重定向。由于 Nuget 客户端存在问题,在辅助角色项目中不会发生这种情况。要解决此问题,请将其添加到辅助角色项目的 app.config 中(或者尝试将 signalR 包添加到控制台应用程序,然后从其 app.config 复制粘贴绑定(bind)重定向):

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.0.2.0" newVersion="2.0.2.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.0.2.0" newVersion="2.0.2.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

关于azure - 使用 F# 在 Azure 辅助角色中托管 SignalR 时出现 FileLoadException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20083185/

相关文章:

c# - 尝试在不存在的网络连接上执行操作

powershell - 获取我的 Azure 订阅中所有资源的列表(最好是 Powershell)

Azure函数: Deploying to stage slot also deploys to production slot

c# - Windows应用程序中的身份验证 "Cannot work with a MobileServiceClient that does not specify a gateway URI."

f# - 为什么 $ 允许但 $$ 或 <$> 不允许作为运算符 (FS0035) 以及 $ 的特殊之处?

.net - F# 编译器是单程编译器吗?

.net - F# 中的函数应用运算符 ($)?

javascript - 当代码在 SignalR 回调中时 AngularJS 绑定(bind)延迟

powershell - 在 Powershell 中处理数组(使用 Pester 进行测试)

asp.net - 在具有多个项目(API/服务/数据等)的解决方案中编写 SignalR 服务的最佳方法是什么?