【问题标题】:Runtime MissingMethodException运行时 MissingMethodException
【发布时间】:2020-05-03 01:03:00
【问题描述】:

在运行使用 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)'.`

感谢任何帮助!

【问题讨论】:

    标签: c# .net visual-studio scripting csharpscript


    【解决方案1】:

    尝试像这样更新程序集

     <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>
    

    引用This answer

    【讨论】:

      猜你喜欢
      • 2018-09-21
      • 1970-01-01
      • 2011-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多