I'm currently trying to use scripts in C # and I have an error as shown below when calling the Test.DoThat method. If I change the DoThat method without a parameter, then it is ok. Please help.
Microsoft.CodeAnalysis.Scripting.CompilationErrorException: '(1,8): error CS1503: argument 1: cannot be converted from' Scripting.Device [Scripting, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = null] 'to' Scripting. Device [C: \ Users \ sheehou \ Documents \ Code \ Scripting \ Scripting \ bin \ Debug \ Scripting.exe] ''
Here is my program:
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();
}
}
}