方法'CommonCreateArrayTypeSymbol'没有实现

时间:2019-10-30 22:59:58

标签: c# csharpscript

我有非常简单的代码,它使用nuget Microsoft.CodeAnalysis.CSharp.Scripting

var script = CSharpScript.Create($@"
IntProp1 = 123;
IntProp2 = 456;
return IntProp1 + IntProp2;
");
var errors = script.Compile();

一个月前,它运行得非常好,突然之间,我开始在这里收到异常消息:

System.TypeLoadException: 'Method 'CommonCreateArrayTypeSymbol' in type 'Microsoft.CodeAnalysis.CSharp.CSharpCompilation' from assembly 'Microsoft.CodeAnalysis.CSharp, Version=3.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.'

2 个答案:

答案 0 :(得分:0)

我发现我的nuget依赖版本不匹配:

<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="3.3.1" />
<PackageReference Include="Microsoft.CodeAnalysis.Compilers" Version="3.1.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="3.1.0" />
<PackageReference Include="Microsoft.CodeAnalysis.Scripting" Version="3.1.0" />
<PackageReference Include="Microsoft.CSharp" Version="4.6.0" />

一旦我将“ Microsoft.CodeAnalysis.Common”从“ 3.3.1”更新为“ 3.1.0”,一切就恢复了正常。

答案 1 :(得分:0)

在一轮 NuGet 包更新之后,我遇到了与 Razor“编辑并继续”或任何他们所说的类似的问题。已解决:

<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="3.11.0" />

在我的主应用程序/网络项目文件中。

我遇到的错误,特别是:

  An unhandled exception has occurred while executing the request.
  System.TypeLoadException: Method 'get_CommonSyntaxTrees' in type 'Microsoft.CodeAnalysis.CSharp.CSharpCompilation' from assembly 'Microsoft.CodeAnalysis.CSharp, Version=3.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.
     at Microsoft.CodeAnalysis.Razor.CompilationTagHelperFeature.GetDescriptors()