Skip to content

Conversation

@rupeshghosh10
Copy link
Contributor

Replace GetEnumValues in the RequiresDynamicCode attribute message on System.Type.GetEnumValues, System.Reflection.SignatureType.GetEnumValues and System.Runtime.GetEnumValues with Enum.GetValues with Enum.GetValues

Fix #86585

Replace GetEnumValues<TEnum> in the RequiresDynamicCode attribute message on System.Type.GetEnumValues, System.Reflection.SignatureType.GetEnumValues and System.Runtime.GetEnumValues with Enum.GetValues<T> with Enum.GetValues<T>

Fix #86585
@ghost ghost added area-NativeAOT-coreclr community-contribution Indicates that the PR has been added by a community member labels May 22, 2023
@ghost
Copy link

ghost commented May 22, 2023

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.

Issue Details

Replace GetEnumValues in the RequiresDynamicCode attribute message on System.Type.GetEnumValues, System.Reflection.SignatureType.GetEnumValues and System.Runtime.GetEnumValues with Enum.GetValues with Enum.GetValues

Fix #86585

Author: RupeshGhosh10
Assignees: -
Labels:

area-NativeAOT-coreclr

Milestone: -

@rupeshghosh10
Copy link
Contributor Author

@dotnet-policy-service agree

public sealed override string[] GetEnumNames() => throw new NotSupportedException(SR.NotSupported_SignatureType);
public sealed override Type GetEnumUnderlyingType() => throw new NotSupportedException(SR.NotSupported_SignatureType);
[RequiresDynamicCode("It might not be possible to create an array of the enum type at runtime. Use the GetEnumValues<TEnum> overload or the GetEnumValuesAsUnderlyingType method instead.")]
[RequiresDynamicCode("It might not be possible to create an array of the enum type at runtime. Use the Enum.GetValues<T> overload or the GetEnumValuesAsUnderlyingType method instead.")]
Copy link
Member

@jkotas jkotas May 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[RequiresDynamicCode("It might not be possible to create an array of the enum type at runtime. Use the Enum.GetValues<T> overload or the GetEnumValuesAsUnderlyingType method instead.")]
[RequiresDynamicCode("It might not be possible to create an array of the enum type at runtime. Use Enum.GetValues<T> or the GetEnumValuesAsUnderlyingType method instead.")]

Enum.GetValues is not overload of the annotated method.

@jkotas
Copy link
Member

jkotas commented May 22, 2023

The same change is going to be needed in the ref assembly too (src\libraries\System.Runtime\ref\System.Runtime.cs).

@jkotas
Copy link
Member

jkotas commented May 22, 2023

Build error:

2023-05-22T19:42:31.9156582Z /__w/1/s/src/libraries/apicompat/ApiCompat.proj(51,5): error CP0015: Cannot change arguments of attribute 'System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute' on 'System.Type.GetEnumValues()'.

This needs to be fixed by adding a warning suppression to src/libraries/apicompat/ApiCompatBaseline.NetCoreAppLatestStable.xml . (For example, look at the suppression added in https://github.com/dotnet/runtime/pull/84369/files for similar problem.)

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@jkotas jkotas merged commit be2c664 into dotnet:main May 23, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Jun 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-NativeAOT-coreclr community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect RequiresDynamicCode attribute on System.Type.GetEnumValues

2 participants