CsExec is rarely useful. Start from menu File / New / Templates / Scripting / "Scripting C#, call any functions". Delete unused examples in the code. Add some references if need. Don't need RegisterNetComComponent.
Simplified template:
Macro Scripting C#, call any functions4
Simplified template:
Macro Scripting C#, call any functions4
;create variable that manages compiled C# code
CsScript x
;optionally set some options
;x.SetOptions("debugConfig=true[]references=System.Data;System.XML")
;compile code after #ret
x.AddCode("")
;call static function
str R=x.Call("Class1.TestFunction" "test" 5)
out R
#ret
//C# code
using System;
public class Class1
{
public static string TestFunction(string s, int i)
{
,Console.Write(s); Console.Write(i); //display in QM output
,return "result";
}
}