Repository navigation
Description
Description
On the Mono runtime, TypeBuilder.CreateType() kills the process with g_error when a method was defined with a type returned by FieldInfo.GetModifiedFieldType() (the repro uses only that API). It prints "Cannot handle corlib user type System.Reflection.ModifiedType" and exits with -1073740791 (0xC0000409). CoreCLR throws NotSupportedException for the same code.
Reproduction Steps
using System;
using System.Reflection;
using System.Reflection.Emit;
public class C
{
public volatile int F;
}
public static class Program
{
public static void Main()
{
Console.WriteLine(System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription);
Type modified = typeof(C).GetField("F")!.GetModifiedFieldType();
Console.WriteLine("modified type: " + modified.GetType().FullName);
AssemblyBuilder ab = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("A"), AssemblyBuilderAccess.Run);
TypeBuilder tb = ab.DefineDynamicModule("m").DefineType("T", TypeAttributes.Public);
try
{
MethodBuilder mb = tb.DefineMethod("M", MethodAttributes.Public, typeof(void), new[] { modified });
Console.WriteLine("DefineMethod returned");
mb.GetILGenerator().Emit(OpCodes.Ret);
Console.WriteLine("calling CreateType");
tb.CreateType();
Console.WriteLine("CreateType returned");
}
catch (Exception e)
{
Console.WriteLine("threw " + e.GetType().FullName + ": " + e.Message);
}
}
}Built for net10.0, run on two .NET 12.0.0-dev Windows x64 test hosts (DOTNET_ROLL_FORWARD=Major, DOTNET_ROLL_FORWARD_TO_PRERELEASE=1): one whose coreclr.dll and System.Private.CoreLib.dll come from a Mono build, and a CoreCLR one.
Expected behavior
An exception, as on CoreCLR, that the caller can catch.
Actual behavior
Mono:
.NET 12.0.0-dev
modified type: System.Reflection.ModifiedType
DefineMethod returned
calling CreateType
Cannot handle corlib user type System.Reflection.ModifiedType
The process exits with -1073740791 inside CreateType(); the catch is not reached.
CoreCLR, same binary:
.NET 12.0.0-dev
modified type: System.Reflection.ModifiedType
DefineMethod returned
calling CreateType
threw System.NotSupportedException: Modified types do not support this member. Use the UnderlyingSystemType property to call this member.
Regression?
Not checked.
Known Workarounds
Not tested.
Configuration
.NET 12.0.0-dev, Windows 11 x64, Mono runtime. Not tried on other OSes or architectures.
Other information
The message comes from the final else branch of mono_reflection_type_handle_mono_type, which branches on the System.Reflection.Emit types it knows and ends in g_error for any other type:
} else {
g_error ("Cannot handle corlib user type %s", mono_type_full_name (m_class_get_byval_arg (mono_handle_class (ref))));Raising a managed exception there instead of g_error would match CoreCLR. #134397 tracks removing selected Mono runtime packs from the .NET 12 official build, so this is reported mainly for the record.
I can implement that change if it is wanted. Could this be assigned to me?
Note
AI-generated, written at my direction and reviewed by me before posting.
The repro was compiled and run as written on both test hosts above. The source link was read at cff49ad0c9cd, the local origin/main on 2026-10-09. A search of dotnet/runtime for the message text and for "corlib user type" returned no issue and no pull request (searched separately, no state filter). Searches for "ModifiedType" with "Mono" or "TypeBuilder" returned items whose titles do not describe this crash (for example #75348, #123819, #121128).
Activity
dotnet-policy-service commentedon Oct 9, 2026
Tagging subscribers to this area: @steveisok, @dotnet/area-system-reflection
See info in area-owners.md if you want to be subscribed.