[Mono-dev] CodeDomProvider.CreateProvider fails on Windows

Frank Fuchs fk.fuchs at googlemail.com
Thu Jul 29 03:25:44 EDT 2010


Hi,

I'd like to compile .cs files at runtime. Following the tip frome here
http://lists.ximian.com/pipermail/mono-devel-list/2010-July/035505.html I'm
able to do that on my Mac. On Windows (win 7 enterprise) however I do not
manage to get it running.
The program exits with exit code 01 right when calling
CodeDomProvider.CreateProvider("C#"). I'm using mono in a relocated setup
(no admin rights on the windows machine).
Strangely the program executes well when I call the assembly with mono from
command line, but fails when calling it from the embedding c++ application
(other calls from this app work well on windows and the mac). Sadly I do not
get any output apart form the exit code, even when using gdb.
Am I missing any initializations? Do I need to tell the program where the
compiler is?

-Frank

using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using System.CodeDom.Compiler;
using System.Reflection;
namespace MonoCSharpCompiler
{
    class Compiler
    {
        public static void Main ()
        {
            string[] rFileNames=new string[2];
            rFileNames[0]="D:\\ScriptTests\\Mono\\auto.cs";
            rFileNames[1]="D:\\ScriptTests\\Mono\\MonoScriptGlue.cs";
            CodeDomProvider provider = CodeDomProvider.CreateProvider
("C#");  // <<<==== IT FAILS HERE
            CompilerParameters parms = new CompilerParameters ();
            parms.GenerateExecutable = true;
            parms.OutputAssembly =
Path.ChangeExtension(rFileNames[0],".exe");
            Console.WriteLine(parms.OutputAssembly);
            CompilerResults cr=provider.CompileAssemblyFromFile(parms,
rFileNames);

            // If errors occurred during compilation, output the compiler
output and errors.
            Console.WriteLine( "Compiler returned with result code: " +
cr.NativeCompilerReturnValue.ToString() );
            foreach ( Object obj in cr.Output )
                 Console.WriteLine( ">{0}", obj );
            Console.WriteLine("");
            if( cr.Errors.Count > 0 )
            {
                for( int i=0; i<cr.Errors.Count; i++ )
                    Console.WriteLine( i.ToString() + ": " +
cr.Errors[i].ToString() );
            }
            else
            {
                // Display information about the compiler's exit code and
the generated assembly.
                Console.WriteLine( "Generated assembly name: " +
cr.CompiledAssembly.FullName );
                if( cr.PathToAssembly == null )
                    Console.WriteLine( "The assembly has been generated in
memory." );
                else
                    Console.WriteLine( "Path to assembly: " +
cr.PathToAssembly );
            }
        }
    }
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20100729/eb65c577/attachment.html 


More information about the Mono-devel-list mailing list