- Home /
Question by
TimyPastek · Mar 09, 2015 at 03:28 PM ·
standalonemonoassemblycompile
How to use CSharpCodeProvider in windows standalone?
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?
Comment
Two and a half years later, this is stall an issue. Ever solve this?
Your answer
Follow this Question
Related Questions
Is there any way to use CSharpCodeProvider in build? 0 Answers
How do you compile a managed dll with mono/mcs targeting .net 2.0 or 3.5 for Unity? 1 Answer
Best way to build a Mono assembly? 1 Answer
Standalone windows build giving mono: dll not found error 2 Answers
Can I use Monodevelop bundled with Unity to debug standalone .NET applications? 0 Answers