[Mono-dev] Unable to use System.Console from embedded

Chase kiro.roo at gmail.com
Wed Jan 13 15:36:01 UTC 2016

Elmar Haneke wrote
> Is it on MS-Windows?
> In this case you have to build an console application else there is no
> Console at all.

I am running this on Windows 7.

The application is not being run as a console app, however the standard
output is being piped to a log file where we are able to receive all cout
and fprintf statements.

After doing a bit of digging last night I found that Mono was outputting
this statement when the System.Console.Write was being executed.
"Assertion at f:\mono-master\mono\metadata\marshal.c:8912, condition
`enter_method' not met"

I looked a bit into the mono code and the "enter_method" appears to be
something that deals with thread locking, which I think the system didn't
init or wasn't able to find.  Though I'm not very familiar with the inner
workings it suggests that something in the setup is not right.

Below is the code I'm using to init the framework.

> //Set dirs
> string rootPath = UtAppInterface::getWorkingDirectory();
> mono_set_dirs((rootPath + "\\mono\\lib\\").c_str(), (rootPath +
> "\\mono\\ect\\").c_str());
> //Create domains
> mainDomain = mono_jit_init("MainDomain");
> //Open
> MonoAssembly* assembly = mono_domain_assembly_open(mainDomain, (rootPath +
> "\\mono\\App.exe").c_str());
> if(!assembly)
> 	return false;
> //Execute
> int argc = 1;
> char* argv = "App.exe";
> auto retval = mono_jit_exec(mainDomain, assembly, argc, &argv);

The App.exe is quite simple.

> using System;
> namespace App
> {
> 	public class MyClass
> 	{
> 		static void Main(string[] args)
> 		{
> 			System.Console.Write ("Hello World");
> 		}
> 	}
> }

View this message in context: http://mono.1490590.n4.nabble.com/Unable-to-use-System-Console-from-embedded-tp4667299p4667301.html
Sent from the Mono - Dev mailing list archive at Nabble.com.

More information about the Mono-devel-list mailing list