Skip to content

Fix Incorrect RequiresDynamicCode attribute message - #86602

Merged
jkotas merged 3 commits into
dotnet:mainfrom
rupeshghosh10:issue-86585
May 23, 2023
Merged

Fix Incorrect RequiresDynamicCode attribute message#86602
jkotas merged 3 commits into
dotnet:mainfrom
rupeshghosh10:issue-86585

Conversation

@rupeshghosh10

Copy link
Copy Markdown
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
@ghostghost added area-NativeAOT-coreclr community-contribution Indicates that the PR has been added by a community member labels May 22, 2023
@ghost

Copy link
Copy Markdown

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
Copy Markdown
ContributorAuthor

@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.")]

@jkotasjkotasMay 22, 2023

Copy link
Copy Markdown
Member

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
Copy Markdown
Member

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

@jkotas

Copy link
Copy Markdown
Member

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.)

@jkotasjkotas left a comment

Copy link
Copy Markdown
Member

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:mainMay 23, 2023
@ghostghost locked as resolved and limited conversation to collaborators Jun 22, 2023
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-NativeAOT-coreclrcommunity-contributionIndicates 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

@rupeshghosh10@jkotas