UnmanagedCallersOnly functions with bool/char parameters should be an error · Issue #64086 · dotnet/roslyn (original) (raw)

Version Used:

Steps to Reproduce:

See:

Code:

using System.Runtime.InteropServices;

class App { public unsafe static void Main () { delegate* unmanaged<bool, void> i = &I; i(true); }

[UnmanagedCallersOnly]
static void I (bool fileRegion)
{
}

}

Note: char has the exact same problem.

Expected Behavior:

A compiler error:

Program.cs(12,20): error CS8894: Cannot use 'bool' as a parameter type on a method attributed with 'UnmanagedCallersOnly'.

Actual Behavior:

Compilation succeeds, but an exception is thrown at runtime:

Unhandled exception. System.InvalidProgramException: Non-blittable parameter types are invalid for UnmanagedCallersOnly methods.
   at App.Main() in /Users/rolf/test/dotnet/console2/Program.cs:line 8

This bug is very similar to #57025, where the same problem occurred, except with ref parameters instead of bool / char parameters.