我在尝试评估CSharpScript时遇到问题。我正在运行dnx46,Microsoft.CodeAnalysis.CSharp 1.2.0-rc。我怀疑mscorlib和CoreFx之间的冲突存在问题。
以下是失败的代码段之一:
private readonly IApplicationEnvironment _environment;
private readonly ILibraryExporter _exporter;
var references = _exporter.GetAllExports(_environment.ApplicationName).MetadataReferences;
var options = ScriptOptions.Default
.AddReferences(references.Select(x => ConvertMetadataReference(x)))
.AddImports("System.Collections.Generic", "System.Linq");
var result = await CSharpScript.EvaluateAsync("1+1");
(我的ApplicationEnvironment和LibraryExporter在启动时由dnx传入,这些都不为null)。
尝试运行CSharpScript.EvaluateAsync
时,会抛出以下异常。
Method not found: 'Void Microsoft.CodeAnalysis.CSharp.CSharpCompilationOptions..ctor
(Microsoft.CodeAnalysis.OutputKind, Boolean, System.String, System.String, System.String,
System.Collections.Generic.IEnumerable`1<System.String>,
Microsoft.CodeAnalysis.OptimizationLevel, Boolean, Boolean, System.String, System.String,
System.Collections.Immutable.ImmutableArray`1<Byte>,
System.Nullable`1<Boolean>, Microsoft.CodeAnalysis.Platform,
Microsoft.CodeAnalysis.ReportDiagnostic,
Int32, System.Collections.Generic.IEnumerable`1
<System.Collections.Generic.KeyValuePair`2
<System.String,Microsoft.CodeAnalysis.ReportDiagnostic>>, Boolean, Boolean,
Microsoft.CodeAnalysis.XmlReferenceResolver,
Microsoft.CodeAnalysis.SourceReferenceResolver,
Microsoft.CodeAnalysis.MetadataReferenceResolver,
Microsoft.CodeAnalysis.AssemblyIdentityComparer,
Microsoft.CodeAnalysis.StrongNameProvider, Boolean)'
我dumped the list of references in my ScriptOptions,不确定是否显示任何内容。
虽然我不确定我的代码是什么问题,但我认为它必须在dnx46下运行这个项目,因为我必须覆盖基本程序集(System,System.Runtime,等我的project.json。
答案 0 :(得分:0)
恢复
"Microsoft.CodeAnalysis.CSharp": "1.1.1",
"Microsoft.CodeAnalysis.CSharp.Scripting": "1.1.1",
"Microsoft.Dnx.Compilation.Abstractions": "1.0.0-rc1-final",
"Microsoft.Dnx.Compilation.CSharp.Abstractions": "1.0.0-rc1-final"
解决了这个问题。
不确定为什么它首先是一个问题,但问题已经解决。