roslyn 依赖是 MissingMethodException

编程入门 行业动态 更新时间:2024-10-09 23:21:30
本文介绍了roslyn 依赖是 MissingMethodException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在升级项目中的依赖项后,roslyn 编译器开始在以下代码中抛出缺少方法异常,更新前有效:

After upgrading the dependencies in project roslyn compiler started to throw missing method exception in the following code that before update worked:

CSharpCompilation compilation = CreateCompilation(templateId, syntaxTrees, metadataReferences); EmitResult compileResult; generatedAssembly = string.Empty; using (var stream = new MemoryStream()) { compileResult = compilation.Emit(stream);

现在它抛出 MissingMethod 异常:

Now its throwing MissingMethod exception:

System.MissingMethodException Method not found: 'System.Collections.Immutable.ImmutableArray`1<Microsoft.CodeAnalysis.Diagnostic> Microsoft.CodeAnalysis.Emit.EmitResult.get_Diagnostics()'.

所有依赖项都更新为当前最新版本:

All the dependencies are updated to current latest versions:

<package id="Microsoft.Bcl.Build" version="1.0.21" targetFramework="net461" /> <package id="Microsoft.CodeAnalysis.Analyzers" version="1.1.0" targetFramework="net461" /> <package id="Microsoft.CodeAnalysis.Common" version="1.3.2" targetFramework="net461" /> <package id="Microsoft.CodeAnalysis.CSharp" version="1.3.2" targetFramework="net461" /> <package id="System.Collections.Immutable" version="1.2.0" targetFramework="net461" />

fds

推荐答案

问题是由 this 引起的roslyn 中的错误,因此添加程序集重定向有帮助:

The issue was caused by this bug in roslyn, so adding an assembly redirects helped:

<dependentAssembly> <assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-1.1.37.0" newVersion="1.1.37.0" /> </dependentAssembly>

但应用仍然使用 1.2.0.0 版本的不可变集合

but the app still uses 1.2.0.0 version of Immutable collections

更多推荐

roslyn 依赖是 MissingMethodException

本文发布于:2023-11-12 13:04:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581580.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:roslyn   MissingMethodException

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!