Hello,
I try to dynamically compile C# code during execution with CSharpCodeProvider.
It work fine in unity Editor but not in windows standalone
My code is :
CSharpCodeProvider provider = new CSharpCodeProvider();
string source = "using System;" +
"public class MyClass" +
"{" +
" public MyClass ()"+
" {" +
" }" +
" public static string log()"+
" {"+
" return \"MyClass.log()\";"+
" }"+
"}";
CompilerParameters cParameters = new CompilerParameters();
cParameters.ReferencedAssemblies.Add( "System.dll" );
cParameters.GenerateExecutable = false;
cParameters.OutputAssembly = "test.dll";
CompilerResults cResults = provider.CompileAssemblyFromSource(cParameters, source);
if (cResults.Errors.HasErrors)
{
foreach (CompilerError ce in cResults.Errors)
Debug.LogWarning ("Errors building :" + ce.ToString ());
} else if (cResults.Errors.HasWarnings)
{
foreach (CompilerError ce in cResults.Errors)
Debug.LogWarning ("Warning building :" + ce.ToString ());
} else
{
Assembly assembly = cResults.CompiledAssembly;
System.Type type = assembly.GetType("MyClass");
Debug.LogWarning( (string) type.InvokeMember("log", BindingFlags.InvokeMethod, null, assembly, null));
}
And I have this error when I use windows standalone:
FileNotFoundException: Windows mono path not found: C:\Users\guillaume\Stage\Projects\GUI3\mono\mono\mini\mono.exe
at Mono.CSharp.CSharpCodeCompiler..cctor () [0x00000] in <filename unknown>:0
Rethrow as TypeInitializationException: An exception was thrown by the type initializer for Mono.CSharp.CSharpCodeCompiler
at Microsoft.CSharp.CSharpCodeProvider.CreateCompiler () [0x00000] in <filename unknown>:0
at System.CodeDom.Compiler.CodeDomProvider.CompileAssemblyFromSource (System.CodeDom.Compiler.CompilerParameters options, System.String[] fileNames) [0x00000] in <filename unknown>:0
at Main.Start () [0x00000] in <filename unknown>:0
(Filename: Line: -1)
NullReferenceException: Object reference not set to an instance of an object
at Main.OnApplicationQuit () [0x00000] in <filename unknown>:0
(Filename: Line: -1)
Anyone having this problem?