在运行使用 CSharpScripting 类的代码时,我们在运行时遇到了一个奇怪的问题。
这是重现错误的示例代码:
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
try
{
// Creating the script
var compiled = CSharpScript.Create<string>(@"return ""ciao"";");
compiled.Compile();
var runner = compiled.CreateDelegate();
var result = runner().GetAwaiter().GetResult();
Assert.AreEqual("ciao", result);
}
catch (Exception ex)
{
}
}
}
测试不运行,它编译但在运行时抛出
System.MissingMethodException: Method not found: 'System.Collections.Immutable.ImmutableArray1<Microsoft.CodeAnalysis.Diagnostic> Microsoft.CodeAnalysis.Scripting.Script.Compile(System.Threading.CancellationToken)'.`
任何帮助表示赞赏!