【问题标题】:FileLoadException when hosting SignalR at Azure Worker Role with F#使用 F# 在 Azure Worker Role 上托管 SignalR 时出现 FileLoadException
【发布时间】:2013-12-03 16:37:31
【问题描述】:

我正在尝试在 Windows Azure Worker 角色中运行 SignalR 自托管服务器,但不断收到

System.IO.FileLoadException:无法加载文件或程序集 'Microsoft.Owin,版本=2.0.0.0,文化=中性, PublicKeyToken=31bf3856ad364e35' 或其依赖项之一。这 定位程序集的清单定义与程序集不匹配 参考。 (HRESULT 异常:0x80131040)

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

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

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

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

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

您知道导致问题的原因或如何进一步诊断吗?

【问题讨论】:

    标签: azure f# signalr owin


    【解决方案1】:

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

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

    【讨论】:

    • 非常感谢!这成功了。我还必须手动将所需的 nuget 包(signalr.selfhost 等)安装到 WorkerRole 项目,即使它们被 WorkerRole 项目引用的另一个库使用。
    • 这里有一个更完整的答案:stackoverflow.com/a/21462519/21539 最好使用 nuget 包管理器来更新 Microsoft.Owin.* 设置,这样您实际上也可以获得更新的二进制文件 :)
    【解决方案2】:

    如果接受的答案对您不起作用,请在包管理器控制台中发出以下 2 个命令:

    update-package Microsoft.Owin -version 2.x.x
    update-package Microsoft.Owin.Security -version 2.x.x
    

    其中 2.x.x 是异常抱怨的版本。

    对我来说,版本号是 2.0.1。

    然后确保您在应用程序的配置文件中包含以下内容(configuration 部分):

    <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.1.0" newVersion="2.x.x.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.x.x.0" />
      </dependentAssembly>
    </assemblyBinding>
    </runtime>
    

    【讨论】:

      【解决方案3】:

      添加上面的绑定并没有解决我的问题。我不得不手动编辑 .csproj 文件。

      • “右键单击”项目并选择“卸载项目”,然后“右键单击”项目并点击“编辑”。

      • 从那里,我必须清理 Owin 程序集的节点。我的 Owin 程序集没有从相关的 NuGet 包目录加载,因此加载的是 2.0.0。

      之前

      -    <Reference Include="Microsoft.Owin">
      -      <HintPath>..\packages\Microsoft.Owin.2.0.0\lib\net45\Microsoft.Owin.dll</HintPath>
      -    </Reference>
      -    <Reference Include="Microsoft.Owin.Host.SystemWeb">
      -      <HintPath>..\packages\Microsoft.Owin.Host.SystemWeb.2.0.0\lib\net45\Microsoft.Owin.Host.SystemWeb.dll</HintPath>
      -    </Reference>
      -    <Reference Include="Microsoft.Owin.Security">
      -      <HintPath>..\packages\Microsoft.Owin.Security.2.0.0\lib\net45\Microsoft.Owin.Security.dll</HintPath>
      -    </Reference>
      -    <Reference Include="Microsoft.Owin.Security.Facebook">
      -      <HintPath>..\packages\Microsoft.Owin.Security.Facebook.2.0.0\lib\net45\Microsoft.Owin.Security.Facebook.dll</HintPath>
      -    </Reference>
      -    <Reference Include="Microsoft.Owin.Security.Cookies">
      -      <HintPath>..\packages\Microsoft.Owin.Security.Cookies.2.0.0\lib\net45\Microsoft.Owin.Security.Cookies.dll</HintPath>
      -    </Reference>
      -    <Reference Include="Microsoft.Owin.Security.OAuth">
      -      <HintPath>..\packages\Microsoft.Owin.Security.OAuth.2.0.0\lib\net45\Microsoft.Owin.Security.OAuth.dll</HintPath>
      -    </Reference>
      

      之后

      +    <Reference Include="Microsoft.AspNet.Identity.Owin">
      +      <HintPath>..\packages\Microsoft.AspNet.Identity.Owin.1.0.0\lib\net45\Microsoft.AspNet.Identity.Owin.dll</HintPath>
      +    </Reference>
      +    <Reference Include="Microsoft.Owin, Version=2.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
      +      <HintPath>..\packages\Microsoft.Owin.2.0.2\lib\net45\Microsoft.Owin.dll</HintPath>
      +    </Reference>
      +    <Reference Include="Microsoft.Owin.Security, Version=2.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
      +      <HintPath>..\packages\Microsoft.Owin.Security.2.0.2\lib\net45\Microsoft.Owin.Security.dll</HintPath>
      +    </Reference>
      +    <Reference Include="Microsoft.Owin.Security.Cookies, Version=2.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
      +      <HintPath>..\packages\Microsoft.Owin.Security.Cookies.2.0.2\lib\net45\Microsoft.Owin.Security.Cookies.dll</HintPath>
      +    </Reference>
      +    <Reference Include="Microsoft.Owin.Security.OAuth, Version=2.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
      +      <HintPath>..\packages\Microsoft.Owin.Security.OAuth.2.0.2\lib\net45\Microsoft.Owin.Security.OAuth.dll</HintPath>
      +    </Reference>
      +    <Reference Include="Microsoft.Owin.Host.SystemWeb, Version=2.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
      +      <HintPath>..\packages\Microsoft.Owin.Host.SystemWeb.2.0.2\lib\net45\Microsoft.Owin.Host.SystemWeb.dll</HintPath>
      +    </Reference>
      
      • 最后,“右键单击”项目并选择“重新加载项目”。
      • 打开项目的“参考”并验证它是否从系统上的正确位置加载正确的版本。

      【讨论】:

        猜你喜欢
        • 2014-04-24
        • 1970-01-01
        • 2015-03-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-04-23
        • 2018-02-05
        相关资源
        最近更新 更多