Skip to content

Incompatibilities between CoreCLR and Mono

Rolf Bjarne Kvinge edited this page May 10, 2022 · 1 revision

Assembly.GetType works differently for nested types

Mono accepts both + and / as the character that separates the declaring type and the nested type, while CoreCLR only accepts /.

Example:

using System;

class Program
{
	class N {}
	static void Main (string[] args)
	{
		Console.WriteLine ($"Program+N: {typeof (Program).Assembly.GetType ("Program+N")}");
		Console.WriteLine ($"Program/N: {typeof (Program).Assembly.GetType ("Program/N")}");
	}
}

Mono prints:

$ mcs Program.cs && mono Program.exe
Program+N: Program+N
Program/N: Program+N

CoreCLR prints:

$ dotnet run
Program+N: Program+N
Program/N: 

It's not possible to pass an Action<T> or a Func<T> to a P/Invoke or Marshal.GetFunctionPointerForDelegate.

Example:

using System;
using System.Runtime.InteropServices;

class App {
    public static void Main ()
    {
        Action<int> a = v => {};
        var p = Marshal.GetFunctionPointerForDelegate (a);
		Console.WriteLine (p);
    }
}

Mono prints:

$ mcs Program.cs && mono Program.exe
4500559232

CoreCLR prints:

$ dotnet run
Unhandled exception. System.ArgumentException: The specified Type must not be a generic type. (Parameter 'delegate')
   at System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegateInternal(Delegate d)
   at System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(Delegate d)
   at System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate[TDelegate](TDelegate d)
   at App.Main() in Program.cs:line 8

Ref: https://github.com/dotnet/runtime/issues/32963

It's not possible to have CoreCLR unwind native frames for managed exceptions.

This means that no entry point into managed code can "leak" exceptions back into native code, because CoreCLR will abort the process.

For Objective-C entry points, Xamarin will catch managed exceptions and convert them to Objective-C exceptions, but this won't be done for reverse P/Invokes in user code.

As a result, the UnwindNativeCode and UnwindManagedCode values for exception marshaling are not valid when using CoreCLR.

Ref: https://github.com/xamarin/xamarin-macios/issues/11344

Clone this wiki locally