Skip to content

Invalid type for MakeGenericMethod is crashing the runtime #71339

@krwq

Description

@krwq

One of the types from the test below is crashing the mono runtime in #71324 (most likely typeof(void))

Specific commit affected
39b0578

Relevant code:

[Theory]
[InlineData(typeof(void))]
[InlineData(typeof(Dictionary<,>))]
[InlineData(typeof(List<>))]
[InlineData(typeof(Nullable<>))]
[InlineData(typeof(int*))]
[InlineData(typeof(RefStruct))]
public static void CreateJsonTypeInfoWithInappropriateTypeThrows(Type type)
{
    Assert.Throws<ArgumentException>(() => JsonTypeInfo.CreateJsonTypeInfo(type, new JsonSerializerOptions()));
}

// JsonTypeInfo.CreateJsonTypeInfo:
if (IsInvalidForSerialization(type)) // it seems it passed the check in the repro
{
    ThrowHelper.ThrowArgumentException_CannotSerializeInvalidType(nameof(type), type, null, null);
}

s_createJsonTypeInfo ??= typeof(JsonTypeInfo).GetMethod(nameof(CreateJsonTypeInfo), new Type[] { typeof(JsonSerializerOptions) })!;
return (JsonTypeInfo)s_createJsonTypeInfo.MakeGenericMethod(type)
    .Invoke(null, new object[] { options })!;

cc: @steveisok @fanyang-mono

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-VM-reflection-monoReflection issues specific to MonoVMin-prThere is an active PR which will close this issue when it is merged

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions