升级项目中的依赖项后,roslyn编译器开始在更新前的代码中抛出缺少的方法异常:
CSharpCompilation compilation = CreateCompilation(templateId, syntaxTrees, metadataReferences);
EmitResult compileResult;
generatedAssembly = string.Empty;
using (var stream = new MemoryStream())
{
compileResult = compilation.Emit(stream);
现在抛出MissingMethod异常:
System.MissingMethodException
Method not found: 'System.Collections.Immutable.ImmutableArray`1<Microsoft.CodeAnalysis.Diagnostic> Microsoft.CodeAnalysis.Emit.EmitResult.get_Diagnostics()'.
所有依赖项都更新为当前最新版本:
<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
答案 0 :(得分:3)
问题是由roslyn中的this bug引起的,因此添加程序集重定向有帮助:
<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版本的Immutable集合