[6.0.2] Add [DynamicDependency] on System.Math for trimming#27098
Merged
roji merged 1 commit intodotnet:release/6.0from Jan 6, 2022
Merged
[6.0.2] Add [DynamicDependency] on System.Math for trimming#27098roji merged 1 commit intodotnet:release/6.0from
roji merged 1 commit intodotnet:release/6.0from
Conversation
Contributor
|
|
Member
Author
|
@hez2010 that's true, but these types don't produce failures for the minimal scenario, unlike with Math. I can successfully run a trimmed application with EF Core 6.0 which executes basic queries (which isn't the case before this PR), and even use DateTime.AddHours. Note that this issue only tracks very basic fixing of the issue - there's no attempt here to make EF Core fully trimming-compatible. That's what #26288 tracks for EF 7 (PR #27099 is out for that). |
AndriySvyryd
approved these changes
Jan 3, 2022
ajcvickers
approved these changes
Jan 4, 2022
3 tasks
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Due to EF Core using wrappers to look up methods via reflection (GetRequiredRuntimeMethod), the linker cannot see the dependency on those methods, and trimmed applications fail
Customer impact
It isn't possible to use EF Core in a trimmed application.
How found
Customer report on 6.0.0.
Regression
Yes, from 5.0. Although EF Core 5.0 was never officially trimming-compatible, at least basic scenarios were possible.
Testing
Coverage will be added in 7.0, where trimming will be a focus. The fix was verified manually.
Note that EF Core 6.0 still won't be fully trimming-compatible, but this unlocks at least the basic scenarios which customers were asking for.
Risk
Very low - the fix only adds an attribute which is meaningful only to the linker.
Details
This uses the [DynamicDependency] attribute to make sure System.Math isn't trimmed when using EF Core.
I'm not quite sure why System.Math is special here - we have other translators which depend on various other things (string, GUID), but with this attribute all SQL Server method/member translators initialize successfully and the query executes.
I've placed the attribute in IMethodCallTranslator to fix this for all providers, rather than requiring every provider to do this (since everyone translates stuff on Math).
Fixes #27097