SignalR控制台应用客户端与服务端版本不兼容报错求解决方案
SignalR客户端服务端版本不兼容解决方案
报错信息:System.InvalidOperationException: You are using a version of the client that isn't compatible with the server. Client version 2.1, server version 1.0
该错误本质是ASP.NET SignalR 1.x和2.x大版本不兼容,结合你.NET Framework 4.7.2控制台应用的环境,可按以下步骤解决:
方案1:对齐两端SignalR版本
SignalR 1.x和2.x没有向下兼容性,必须保证客户端和服务端使用的大版本完全一致:- 若保留服务端1.x版本:卸载客户端当前安装的2.1版本
Microsoft.AspNet.SignalR.ClientNuGet包,安装和服务端版本匹配的1.x版本包即可 - 若保留客户端2.1版本:将服务端所有
Microsoft.AspNet.SignalR相关依赖包升级到2.x版本,和客户端版本对齐
- 若保留服务端1.x版本:卸载客户端当前安装的2.1版本
方案2:补充控制台应用程序集重定向配置
控制台应用默认携带App.config文件而非web.config,你可以在该文件中添加程序集重定向规则,避免运行时加载错误版本的SignalR程序集:<configuration> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="Microsoft.AspNet.SignalR.Client" publicKeyToken="31bf3856ad364e35" culture="neutral" /> <!-- 下方newVersion替换为你实际安装的客户端版本号 --> <bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" /> </dependentAssembly> </assemblyBinding> </runtime> </configuration>额外排查项
若确认版本对齐后仍报错,需确认服务端类型:ASP.NET Core SignalR与传统ASP.NET SignalR完全不兼容,若服务端为ASP.NET Core开发,需将客户端包替换为Microsoft.AspNetCore.SignalR.Client,且版本与服务端ASP.NET Core版本匹配。
内容的提问来源于stack exchange,提问作者user17450256
相关产品推荐
相关产品推荐

