调试Xamarin Form SignalR客户端出现System.Numerics.Vectors版本冲突如何解决
问题原因解答
这个System.Numerics.Vectors版本冲突警告就是导致你SignalR客户端无法连接Hub的直接原因。
你使用的6.0预览版SignalR.Client依赖的System.Text.Json组件要求调用System.Numerics.Vectors 4.1.3.0版本的API,但当前编译时优先选择了MonoAndroid框架自带的2.0.5.0旧版本,版本不匹配导致SignalR握手阶段的Json序列化/反序列化逻辑执行异常,无法完成和服务端Hub的连接建立。
修复步骤
- 首先替换所有SignalR相关Nuget包为正式稳定版,移除当前使用的6.0.0-preview.7预览版包,推荐使用和你服务端Asp.Net Core版本匹配的正式版SignalR.Client,避免预览版的兼容缺陷。
- 在Android项目根目录下添加(或修改)
app.config文件,添加程序集绑定重定向规则,强制所有调用指向4.1.3.0版本,规则如下:
<runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="System.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-4.1.3.0" newVersion="4.1.3.0" /> </dependentAssembly> </assemblyBinding> </runtime>
- 给你的Xamarin共享库和Android项目都通过Nuget安装
System.Numerics.Vectors 4.1.3.0版本,覆盖MonoAndroid默认的旧版本引用。 - 完成上述操作后,删除所有项目的
bin、obj缓存文件夹,重启Visual Studio后重新编译运行即可。
内容的提问来源于stack exchange,提问作者Steven-Carrot
相关产品推荐
相关产品推荐

