c# - 运行时 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)'.`
任何帮助表示赞赏!
解决方案
Try Update assembly Like this
<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>
Refrenced This answer
推荐阅读
- ios - 带有 typealias 的协议中的 AssociatedType
- python - 在哪里可以找到 hive url、用户名和密码?
- shell - 解析 Nagios 配置文件
- java - 如何解决声纳问题“删除此调用以“等待”或将其移动到“while”循环中?
- ruby-on-rails - 如何将 Rails(docker 外部)与 Postgres(docker 内部)一起使用?
- fftw - 正向和反向快速傅里叶变换,半周期移位
- c# - 在asp.net中计算在线考试网站的百分比并显示正确答案
- qt - 从深度嵌套的 QVariant 中更改和删除值
- typescript - 打字稿定义(xxx.d.ts)
- linux - 使用 linux GNU 并行后使用“等待”有用吗?