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

Add IsDynamicCodeSupported Feature Switch #80246

Merged
merged 6 commits into from
Jan 9, 2023
Merged

Conversation

eerhardt
Copy link
Member

@eerhardt eerhardt commented Jan 5, 2023

This adds the ability to disable reflection emit for testing. It also allows for applications/libraries to simulate NativeAOT behavior (like switching on RuntimeFeature.IsDynamicCodeSupported) without actually publishing for NativeAOT.

Fix #39806

See also dotnet/sdk#29785 for the SDK support for this feature switch.

This adds the ability to disable reflection emit for testing. It also allows for applications/libraries to simulate NativeAOT behavior (like switching on RuntimeFeature.IsDynamicCodeSupported) without actually publishing for NativeAOT.

Fix dotnet#39806
@ghost
Copy link

ghost commented Jan 5, 2023

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

Issue Details

This adds the ability to disable reflection emit for testing. It also allows for applications/libraries to simulate NativeAOT behavior (like switching on RuntimeFeature.IsDynamicCodeSupported) without actually publishing for NativeAOT.

Fix #39806

Author: eerhardt
Assignees: -
Labels:

area-System.Reflection.Emit

Milestone: -

@eerhardt eerhardt marked this pull request as ready for review January 5, 2023 23:53
@jkotas
Copy link
Member

jkotas commented Jan 6, 2023

Non-Mono part LGTM

@runfoapp runfoapp bot mentioned this pull request Jan 6, 2023
@eerhardt
Copy link
Member Author

eerhardt commented Jan 9, 2023

runtime (Build Linux arm64 Release AllSubsets_Mono_LLVMFullAot_RuntimeTests llvmfullaot) timed out, but passed previously before the last IntrinsicAttribute change. Merging.

@eerhardt eerhardt merged commit df9de14 into dotnet:main Jan 9, 2023
@eerhardt eerhardt deleted the Fix39806 branch January 9, 2023 20:42
eerhardt added a commit to dotnet/sdk that referenced this pull request Jan 9, 2023
Adds support in the SDK for the new RuntimeFeature.IsDynamicCodeSupported feature switch added in dotnet/runtime#80246. When PublishAot is set in a project, DynamicCodeSupport gets defaulted to false.
eerhardt added a commit that referenced this pull request Jan 10, 2023
…ion (#79425)

* Remove RequiresDynamicCode from Microsoft.Extensions.DependencyInjection

We need a better approach in order to support applications that use DependencyInjection and publish for NativeAOT. DependencyInjection needs to have reliable behavior before and after publishing for NativeAOT. The application can't work successfully at development-time, but then fail after publishing with PublishAot=true.

We will resolve the 2 NativeAOT warnings above by adding a runtime check that is behind the new AppContext switch added in #80246 (`System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported`). The runtime check ensures the Types being used with Enumerable and Open Generic services are only Reference Types. If an application tries to create an Enumerable or Closed Generic service of a ValueType, DependencyInjection will throw an exception. The check is enabled by default when PublishAot=true.

Fix #79286
@ghost ghost locked as resolved and limited conversation to collaborators Feb 9, 2023
@jonathanpeppers
Copy link
Member

@eerhardt did we opt into this by default on Mono? I think I might need to turn this off for Android apps (haven't checked iOS yet).

@eerhardt
Copy link
Member Author

I only set DynamicCodeSupport=false when PublishAot=true. See https://github.com/dotnet/sdk/pull/29785/files#diff-946cba6640de0522dafbdd3ab4294eeb086609079f451068ab0b575ade3442c0R22

My understanding is that Mono doesn't use the PublishAot MSBuild property - only "CoreCLR's NativeAOT" feature.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add ability to disable reflection emit for testing
7 participants