由于System.Collections.Immutable,无法使CSharpScript.EvaluateAsync工作 [英] Cannot get CSharpScript.EvaluateAsync to work because of System.Collections.Immutable

查看:351
本文介绍了由于System.Collections.Immutable,无法使CSharpScript.EvaluateAsync工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用DotNet框架4.7.1构建了一个简单的C#COM服务器


它有多种方法,一切正常。但是,我添加了一个方法来使用Roslyn,如下所示:


int result1 = CSharpScript.EvaluateAsync< int>(" 2 + 2")。结果;


但是当从另一个C#程序调用时,如此测试:


对象result2 = com.GetType()。InvokeMember(" EvaluateTest",BindingFlags.Default | BindingFlags.InvokeMethod ,null,ssicom,null);


它失败了:


System.IO.FileNotFoundException:'无法加载文件或程序集'系统。 Collections.Immutable,Version = 1.2.1.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'或其依赖项之一。系统找不到指定的文件。'¥


现在我知道GAC中的错误版本(1.1.37)。


我现在尝试了多个不同的Nuget包组合来支持Roslyn,包括测试版。似乎没有什么摆脱System.Collections.Immutable 1.2.1.0参考。但是Nuget中甚至不存在1.2.1。


是时候完全放弃Roslyn了吗?


解决方案

BTW,ASMSpy显示:


参考:System.Collections.Immutable

  System.Collections.Immutable,Version = 1.2.1.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a

来源:NotFound

  &NBSP; 1.2.1.0 by Microsoft.CodeAnalysis,Version = 2.8.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35

  &NBSP; 1.2.1.0 by Microsoft.CodeAnalysis.CSharp,Version = 2.8.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35

  &NBSP; 1.2.1.0 by Microsoft.CodeAnalysis.CSharp.Scripting,Version = 2.8.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35

  &NBSP; 1.2.1.0 by Microsoft.CodeAnalysis.Scripting,Version = 2.8.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35

  System.Collections.Immutable,Version = 1.2.3.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a

来源:本地,位置:C:\Dev \ Project \ bin \Debug \ System .Collections.Immutable.dll

  &NBSP; 1.2.3.0 by MyCOM,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = 5ffb4e07ca4e717d

  &NBSP; 1.2.3.0 by System.Reflection.Metadata,Version = 1.4.3.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a


我确实尝试过多个版本的Microsoft.CodeAnalysis及其子类。 / p>

声明

int result1 = CSharpScript.EvaluateAsync< int>(" 2 + 2")。结果;


在独立的控制台应用程序中运行。但在COM服务器内部,情况有所不同。


I built a simple C# COM Server using DotNet framework 4.7.1

It has multiple methods and all work ok. However, I added a method to use Roslyn like so:

int result1 = CSharpScript.EvaluateAsync<int>("2 + 2").Result;

But when called from another C# program to test like so:

Object result2 = com.GetType().InvokeMember("EvaluateTest", BindingFlags.Default | BindingFlags.InvokeMethod, null, ssicom, null);

it fails with:

System.IO.FileNotFoundException: 'Could not load file or assembly 'System.Collections.Immutable, Version=1.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.'

Now I know about the wrong version being in the GAC (1.1.37).

I have now tried multiple different Nuget package combinations of the packages to support Roslyn including the beta version. Nothing seems to get rid of the System.Collections.Immutable 1.2.1.0 reference. But 1.2.1 does not even exist in Nuget.

Is it time to abandon Roslyn completely?

解决方案

BTW, ASMSpy shows:

Reference: System.Collections.Immutable
  System.Collections.Immutable, Version=1.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Source: NotFound
    1.2.1.0 by Microsoft.CodeAnalysis, Version=2.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
    1.2.1.0 by Microsoft.CodeAnalysis.CSharp, Version=2.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
    1.2.1.0 by Microsoft.CodeAnalysis.CSharp.Scripting, Version=2.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
    1.2.1.0 by Microsoft.CodeAnalysis.Scripting, Version=2.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
  System.Collections.Immutable, Version=1.2.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Source: Local, Location: C:\Dev\Project\bin\Debug\System.Collections.Immutable.dll
    1.2.3.0 by MyCOM, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5ffb4e07ca4e717d
    1.2.3.0 by System.Reflection.Metadata, Version=1.4.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

And I did try multiple versions of Microsoft.CodeAnalysis and its subclasses.

The statement
int result1 = CSharpScript.EvaluateAsync<int>("2 + 2").Result;

works in a standalone Console application. But inside the COM server, something is different.


这篇关于由于System.Collections.Immutable,无法使CSharpScript.EvaluateAsync工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆