-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
[6.0.2] Add [DynamicDependency] on System.Math for trimming #27098
Conversation
|
@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). |
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