我正在尝试使用C#脚本,当调用Test.DoThat方法时,我有如下错误。如果我将DoThat方法更改为不带参数,那么它是o.k.请帮忙。
Microsoft.CodeAnalysis.Scripting.CompilationErrorException:'(1,8):error CS1503:参数1:无法从'Scripting.Device [Scripting,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null]'转换为'Scripting.Device [C:\ Users \ sheehou \ Documents \ Code \ Scripting \ Scripting \ bin \ Debug \ Scripting.exe]''
这是我的计划:
using System;
using Microsoft.CodeAnalysis.Scripting;
using Microsoft.CodeAnalysis.CSharp.Scripting;
namespace Scripting
{
public class Device
{
public string GetMessage()
{
return "Device";
}
}
public class Test
{
public void DoThat(Device dev)
{
Console.WriteLine(dev.GetMessage());
}
}
class Program6
{
static void Main(string[] args)
{
var test = new Test();
var options = ScriptOptions.Default.AddReferences(typeof(Test).Assembly);
var state = CSharpScript.RunAsync("", options, test, typeof(Test)).Result;
state = state.ContinueWithAsync("using Scripting;").Result;
state = state.ContinueWithAsync("Device dev = new Device();").Result;
state = state.ContinueWithAsync("DoThat(dev);").Result;
Console.Read();
}
}
}