Skip to content

Func<T>.MakeGenericType(typeof(ReadOnlySpan<char>)) throws ArgumentException in 7.0.100-preview.4 while the exception was TypeLoadException in prior versions #69084

@daxian-dbw

Description

@daxian-dbw

Description

Func<T>.MakeGenericType(typeof(ReadOnlySpan<char>)) (or calling MakeGenericType with any other byref-like value types) throws ArgumentException in 7.0.100-preview.4 while the exception was TypeLoadException in prior versions.

It turns out the ArgumentException wraps a TypeLoadException in its inner exception property.

Reproduction Steps

In PowerShell with 7.0.100-preview.4:

PS:> try { [Func`1].MakeGenericType([System.ReadOnlySpan[char]]) } catch { $a = $_ }
PS:> $a.Exception.InnerException.GetType()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     ArgumentException                        System.SystemException

In PowerShell with .NET 6 and prior 7-preview versions

PS:> try { [Func`1].MakeGenericType([System.ReadOnlySpan[char]]) } catch { $a = $_ }
PS:> $a.Exception.InnerException.GetType()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     TypeLoadException                        System.SystemException

Expected behavior

Throw TypeLoadException as in the prior versions.

Actual behavior

Throw ArgumentException in 7.preview-4
Not sure if this is an intentional change, or a real regression.

Regression?

Yes

Known Workarounds

We can work around by catch all exceptions.

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions