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

Fix Incorrect RequiresDynamicCode attribute message #86602

Merged
merged 3 commits into from May 23, 2023
Merged

Fix Incorrect RequiresDynamicCode attribute message #86602

merged 3 commits into from May 23, 2023

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 the community-contribution Indicates that the PR has been added by a community member label 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

@@ -99,7 +99,7 @@ public sealed override Type MakeArrayType(int rank)
public sealed override string GetEnumName(object value) => throw new NotSupportedException(SR.NotSupported_SignatureType);
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
165 of 168 checks passed
@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