-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Add RequiresDynamicCodeAttribute #61239
Labels
api-approved
API was approved in API review, it can be implemented
api-suggestion
Early API idea and discussion, it is NOT ready for implementation
area-NativeAOT-coreclr
Milestone
Comments
MichalStrehovsky
added
api-suggestion
Early API idea and discussion, it is NOT ready for implementation
api-ready-for-review
API is ready for review, it is NOT ready for implementation
area-NativeAOT-coreclr
labels
Nov 5, 2021
dotnet-issue-labeler
bot
added
the
untriaged
New issue has not been triaged by the area owner
label
Nov 5, 2021
MichalStrehovsky
removed
the
untriaged
New issue has not been triaged by the area owner
label
Nov 5, 2021
Very nice! |
Nit: "dynamic code" is a little vague, maybe |
I chose this name as a complement to the existing |
I think proposals like this one should come together with analyzer proposal. |
Looks good as proposed. namespace System.Diagnostics.CodeAnalysis
{
/// <summary>
/// Indicates that the specified method requires the ability to generate new code at runtime,
/// for example through <see cref="System.Reflection"/>.
/// </summary>
/// <remarks>
/// This allows tools to understand which methods are unsafe to call when compiling ahead of time.
/// </remarks>
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor, Inherited = false)]
public sealed class RequiresDynamicCodeAttribute : Attribute
{
/// <summary>
/// Initializes a new instance of the <see cref="RequiresDynamicCodeAttribute"/> class
/// with the specified message.
/// </summary>
/// <param name="message">
/// A message that contains information about the usage of dynamic code.
/// </param>
public RequiresDynamicCodeAttribute(string message)
{
Message = message;
}
/// <summary>
/// Gets a message that contains information about the usage of dynamic code.
/// </summary>
public string Message { get; }
/// <summary>
/// Gets or sets an optional URL that contains more information about the method,
/// why it requries dynamic code, and what options a consumer has to deal with it.
/// </summary>
public string? Url { get; set; }
}
} |
bartonjs
added
api-approved
API was approved in API review, it can be implemented
and removed
api-ready-for-review
API is ready for review, it is NOT ready for implementation
labels
Nov 16, 2021
Closing via #61956 |
ghost
locked as resolved and limited conversation to collaborators
Dec 25, 2021
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
api-approved
API was approved in API review, it can be implemented
api-suggestion
Early API idea and discussion, it is NOT ready for implementation
area-NativeAOT-coreclr
Background and motivation
.NET comes with APIs that are fundamentally unsupportable without some sort of ability to run dynamic code. We already offer ability to not enable dynamic code support in some of our existing AOT form factors (Xamarin iOS without MtouchInterpreter enabled), and we have other runtime form factors on the horizon (#61231) without dynamic code support by default.
Customers currently don't have a way to tell whether a dynamic-code-less deployment option is a good fit for their app. They need to try and thoroughly test.
We need to introduce API annotations for AOT form factor. These should mirror the annotations introduced for single file and trimming in the past.
API Proposal
API Usage
Assume
DynamicMethod
constructor was annotated withRequiresDynamicCode
:Appropriate tooling (Roslyn analyzer, AOT compiler) would generate a warnings that DynamicMethod requires dynamic code. The user would be able to either:
RequiresDynamicCode
.RuntimeFeature.IsDynamicCodeSupported
checkThe expectation is to mostly mirror
RequiresAssemblyFilesAttribute
/RequiresUnreferencedCodeAttribute
.Alternative Designs
No response
Risks
No response
The text was updated successfully, but these errors were encountered: