我正在尝试在Windows Azure辅助角色中运行SignalR自主服务器,但继续获取
System.IO.FileLoadException:无法加载文件或程序集 'Microsoft.Owin,Version = 2.0.0.0,Culture = neutral, PublicKeyToken = 31bf3856ad364e35'或其依赖项之一。该 找到程序集的清单定义与程序集不匹配 参考。 (HRESULT异常:0x80131040)
当我在控制台应用程序中运行相同的代码时,它运行正常,一切都按预期工作。整个工作者角色用F#编写。下面是产生我正在谈论的例外的最短代码:
override wr.Run() =
let x : IAppBuilder = null
x.MapSignalR() |> ignore // this line throws the FileLoadException
当然上面的代码不起作用,但有不同的例外。通常我在Startup类的Configuration()方法中调用MapSignalR(WebApp.Start(url))。
我粘贴的异常详细信息来自Compute模拟器,但我在实时云服务中获得相同的内容。
您是否知道可能导致问题的原因或我如何进一步诊断?
答案 0 :(得分:7)
这是Nuget的一个已知问题:请参阅this。绑定重定向不会自动添加到工作者角色项目中。这种失败的原因是SignalR二进制文件是依赖于Microsoft.Owin版本2.0.0构建的。但公共源中最新的Microsoft.Owin版本是2.0.2。要在控制台应用程序或Web应用程序上安装相同的SignalR软件包时修复此程序集绑定问题,您将在app.config中看到自动为您添加的程序集绑定重定向。由于Nuget客户端存在问题,因此在工作者角色项目中不会发生这种情况。要解决此问题,请将此添加到您的worker角色项目的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>
答案 1 :(得分:0)
如果接受的答案不起作用,请在程序包管理器控制台中发出以下两个命令:
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>
答案 2 :(得分:0)
添加上面的绑定并没有解决我的问题。我不得不手动编辑.csproj文件。
'右键单击'项目并选择'卸载项目'然后'右键单击'项目并点击“编辑”。
从那里,我不得不清理Owin程序集的节点。我的Owin程序集没有从相关的NuGet包目录加载,因此加载了2.0.0。
<强> BEFORE 强>:
- <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>
<强> AFTER 强>:
+ <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>