我正在尝试从单声道的C API编译C#源代码。请参阅下面的代码。
//System.CodeDom.Compiler.CompilerParameters parameters = new CompilerParameters();
MonoClass* pCompilerParamsClass = mono_class_from_name (pSystemImage, "System.CodeDom.Compiler", "CompilerParameters");
MonoObject* pCompilerParams = mono_object_new (pDomain, pCompilerParamsClass);
mono_runtime_object_init (pCompilerParams);
//parameters.GenerateExecutable = true;
//parameters.OutputAssembly = "Rules.dll";
SetBoolProperty(pCompilerParams, pCompilerParamsClass, "System.CodeDom.Compiler.CompilerParameters:set_GenerateExecutable", true);
SetStringProperty(pCompilerParams, pCompilerParamsClass, "System.CodeDom.Compiler.CompilerParameters:set_OutputAssembly", "Rules.dll");
//string sourceString = "class A {}"
MonoString* pSourceString = mono_string_new(pDomain, "class A {}");
//CSharpCodeProvider codeProvider = new CSharpCodeProvider();
MonoClass* pCodeProviderClass = mono_class_from_name (pSystemImage, "System.CodeDom.Compiler", "CodeDomProvider");
MonoClass* pCSharpCodeProviderClass = mono_class_from_name (pSystemImage, "Microsoft.CSharp", "CSharpCodeProvider");
MonoObject* pCodeProvider = mono_object_new (pDomain, pCSharpCodeProviderClass);
mono_runtime_object_init (pCodeProvider);
//ICodeCompiler icc = codeProvider.CreateCompiler();
MonoMethodDesc* pMethodDescCreateCompiler = mono_method_desc_new("System.CodeDom.Compiler.CodeDomProvider:CreateCompiler()", false);
MonoMethod* pMethodCreateCompiler = mono_method_desc_search_in_class (pMethodDescCreateCompiler, pCSharpCodeProviderClass);
MonoObject* pIcc = mono_runtime_invoke(pMethodCreateCompiler, pCodeProvider, NULL, NULL);
//icc.CompileAssemblyFromSource(parameters, source)
MonoMethodDesc* pMethodDescCompileAssemblyFromSource = mono_method_desc_new("System.CodeDom.Compiler.ICodeCompiler:CompileAssemblyFromSource()", false);
MonoMethod* pMethodCompileAssemblyFromSource = mono_method_desc_search_in_class (pMethodDescCreateCompiler, mono_object_get_class(pIcc));
MonoArray* pParams = mono_array_new(pDomain, mono_get_object_class(), 2);
mono_array_set(pParams, MonoObject*, 0, pCompilerParams);
mono_array_set(pParams, MonoString*, 0, pSourceString);
mono_runtime_invoke_array(pMethodCompileAssemblyFromSource, pCodeProvider, NULL, NULL);
此代码在MonoObject * pIcc = mono_runtime_invoke(pMethodCreateCompiler,pCodeProvider,NULL,NULL)失败;线。
我做错了什么?