簡體   English   中英

運行時缺少方法異常

[英]Runtime MissingMethodException

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

任何幫助表示贊賞!

嘗試像這樣更新程序集

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

參考這個答案

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM