Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MetadataLoadContext: IsValueType: NotSupportedException: Modified types do not support this member #83679

Closed
ericsink opened this issue Mar 20, 2023 · 2 comments · Fixed by #83850

Comments

@ericsink
Copy link

Description

I just updated some things to net8.0 preview 2 with System.Reflection.MetadataLoadContext preview 2. I'm using S.R.MDLC to load all the reference assemblies and process them.

There are several places now where I am now seeing the following exception:

Unhandled exception: System.NotSupportedException: Modified types do not support this member. Use the UnderlyingSystemType property to call this member.
   at System.Reflection.RoModifiedType.Equals(Type other)
   at System.Reflection.TypeLoading.RoType.ComputeBaseTypeClassification()
   at System.Reflection.TypeLoading.RoType.IsValueTypeImpl()
   at System.Reflection.NullabilityInfoContext.GetNullabilityInfo(MemberInfo memberInfo, Type type, NullableAttributeStateParser parser, Int32& index)
   at System.Reflection.NullabilityInfoContext.Create(ParameterInfo parameterInfo)

The exception is thrown when I try to retrieve nullability info for a parameter, but it can also be triggered by simply using IsValueType.

One place it happens is on the value parameter of System.Runtime.InteropServices.SequenceMarshal.TryRead. There are several others. The repro project will dump out a list of them.

I'm just coming up to speed on the new "modified types" stuff, and I see that they don't support equality, and that's what the exception is saying. What I cannot figure out is why a modified type is in play here. Or how I might detect that situation and use the APIs differently to avoid the problem.

Reproduction Steps

repro.zip

Run this console app with the path of the targeting pack as its first argument. For example:

dotnet run /usr/local/share/dotnet/packs/Microsoft.NETCore.App.Ref/8.0.0-preview.2.23128.3/ref/net8.0

Expected behavior

IsValueType on the parameter type should not throw.

Actual behavior

System.NotSupportedException: Modified types do not support this member.

Regression?

Yes, I think this is a regression of sorts.

The crash does NOT occur with System.Reflection.MetadataLoadContext 8.0.0-preview.1.23110.8

The crash DOES occur with System.Reflection.MetadataLoadContext 8.0.0-preview.2.23128.3

Known Workarounds

No response

Configuration

.NET 8 Preview 2

macOS arm64

I haven't tried this on Windows or Linux yet.

Other information

No response

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Mar 20, 2023
@ghost
Copy link

ghost commented Mar 20, 2023

Tagging subscribers to this area: @dotnet/area-system-reflection
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

I just updated some things to net8.0 preview 2 with System.Reflection.MetadataLoadContext preview 2. I'm using S.R.MDLC to load all the reference assemblies and process them.

There are several places now where I am now seeing the following exception:

Unhandled exception: System.NotSupportedException: Modified types do not support this member. Use the UnderlyingSystemType property to call this member.
   at System.Reflection.RoModifiedType.Equals(Type other)
   at System.Reflection.TypeLoading.RoType.ComputeBaseTypeClassification()
   at System.Reflection.TypeLoading.RoType.IsValueTypeImpl()
   at System.Reflection.NullabilityInfoContext.GetNullabilityInfo(MemberInfo memberInfo, Type type, NullableAttributeStateParser parser, Int32& index)
   at System.Reflection.NullabilityInfoContext.Create(ParameterInfo parameterInfo)

The exception is thrown when I try to retrieve nullability info for a parameter, but it can also be triggered by simply using IsValueType.

One place it happens is on the value parameter of System.Runtime.InteropServices.SequenceMarshal.TryRead. There are several others. The repro project will dump out a list of them.

I'm just coming up to speed on the new "modified types" stuff, and I see that they don't support equality, and that's what the exception is saying. What I cannot figure out is why a modified type is in play here. Or how I might detect that situation and use the APIs differently to avoid the problem.

Reproduction Steps

repro.zip

Run this console app with the path of the targeting pack as its first argument. For example:

dotnet run /usr/local/share/dotnet/packs/Microsoft.NETCore.App.Ref/8.0.0-preview.2.23128.3/ref/net8.0

Expected behavior

IsValueType on the parameter type should not throw.

Actual behavior

System.NotSupportedException: Modified types do not support this member.

Regression?

Yes, I think this is a regression of sorts.

The crash does NOT occur with System.Reflection.MetadataLoadContext 8.0.0-preview.1.23110.8

The crash DOES occur with System.Reflection.MetadataLoadContext 8.0.0-preview.2.23128.3

Known Workarounds

No response

Configuration

.NET 8 Preview 2

macOS arm64

I haven't tried this on Windows or Linux yet.

Other information

No response

Author: ericsink
Assignees: -
Labels:

area-System.Reflection

Milestone: -

@steveharter steveharter self-assigned this Mar 22, 2023
@steveharter steveharter removed the untriaged New issue has not been triaged by the area owner label Mar 22, 2023
@steveharter steveharter added this to the 8.0.0 milestone Mar 22, 2023
@steveharter
Copy link
Member

@ericsink thanks for the wonderful repro.

@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Mar 23, 2023
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Mar 24, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Apr 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants