[Mono-dev] Invoking .net interface method from c api

zebrajap zebrajap at yahoo.com
Wed Aug 19 06:39:53 UTC 2015


I am trying to compile a source from c API of mono. Please see my code below.

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	//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);
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

This code fails at MonoObject* pIcc =
mono_runtime_invoke(pMethodCreateCompiler, pCodeProvider, NULL, NULL); line.
What am I doing wrong.

Thanks.





--
View this message in context: http://mono.1490590.n4.nabble.com/Invoking-net-interface-method-from-c-api-tp4666493.html
Sent from the Mono - Dev mailing list archive at Nabble.com.


More information about the Mono-devel-list mailing list