Unity搭配VS Code时Omnisharp报System.Numerics.Vectors版本错误致Intellisense失效
根因说明
该错误由VS Code C#扩展自带的OmniSharp服务与Unity开发环境不兼容导致,1.23.13及以上版本的C#扩展都会触发该System.Numerics.Vectors程序集版本不匹配问题。
修复步骤
- 降级C#扩展到1.23.12版本
打开VS Code扩展面板,搜索C#,点击扩展卡片的齿轮图标,选择「安装另一个版本」,选中1.23.12版本安装后重启VS Code,绝大多数该类问题都会直接解决 - 降级后仍报错的调整配置
打开VS Code设置,搜索omnisharp.useModernNet,取消勾选该选项,强制OmniSharp使用Mono运行时适配Unity的运行环境 - 仍未解决则清除缓存重装
进入目录C:\Users\你的用户名\.vscode\extensions\,删除所有前缀为ms-dotnettools.csharp的文件夹,重启VS Code后重新安装1.23.12版本的C#扩展即可
原始报错信息
System.IO.FileLoadException: Could not load file or assembly 'System.Numerics.Vectors, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) File name: 'System.Numerics.Vectors, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' at System.SpanHelpers.SequenceEqual(Byte& first, Byte& second, NUInt length) at Microsoft.Extensions.DependencyModel.DependencyContextJsonReader.ReadToEnd(Stream stream) at Microsoft.Extensions.DependencyModel.DependencyContextJsonReader.Read(Stream stream) at Microsoft.Extensions.DependencyModel.DependencyContextLoader.LoadAssemblyContext(Assembly assembly, IDependencyContextReader reader) at Microsoft.Extensions.DependencyModel.DependencyContextLoader.Load(Assembly assembly) at Microsoft.Extensions.DependencyModel.DependencyContext.LoadDefault() at System.Lazy`1.CreateValue() at System.Lazy`1.LazyInitValue() at OmniSharp.CompositionHostBuilder.DiscoverOmniSharpAssemblies() in D:\a\1\s\src\OmniSharp.Host\CompositionHostBuilder.cs:line 205 at OmniSharp.CompositionHostBuilder.WithOmniSharpAssemblies() in D:\a\1\s\src\OmniSharp.Host\CompositionHostBuilder.cs:line 179 at OmniSharp.Stdio.Driver.Program.<>c__DisplayClass0_1.<Main>b__1() in D:\a\1\s\src\OmniSharp.Stdio.Driver\Program.cs:line 56 at McMaster.Extensions.CommandLineUtils.CommandLineApplication.<>c__DisplayClass146_0.<OnExecute>b__0(CancellationToken _) at McMaster.Extensions.CommandLineUtils.CommandLineApplication.<ExecuteAsync>d__157.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args) at OmniSharp.HostHelpers.Start(Func`1 action) in D:\a\1\s\src\OmniSharp.Host\HostHelpers.cs:line 29 === Pre-bind state information === LOG: DisplayName = System.Numerics.Vectors, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a (Fully-specified) LOG: Appbase = file:///c:/Users/shaun/.vscode/extensions/ms-dotnettools.csharp-1.23.15/.omnisharp/1.37.15/ LOG: Initial PrivatePath = NULL Calling assembly : System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51. === LOG: This bind starts in default load context. LOG: Using application configuration file: c:\Users\shaun\.vscode\extensions\ms-dotnettools.csharp-1.23.15\.omnisharp\1.37.15\OmniSharp.exe.Config LOG: Using host configuration file: LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config. LOG: The same bind was seen before, and was failed with hr = 0x80131040.
内容的提问来源于stack exchange,提问作者blissweb
相关产品推荐
相关产品推荐

