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

[6.0.2] Add [DynamicDependency] on System.Math for trimming #27098

Merged
merged 1 commit into from
Jan 6, 2022

Conversation

roji
Copy link
Member

@roji roji commented Jan 3, 2022

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

@hez2010
Copy link
Contributor

hez2010 commented Jan 3, 2022

System.DateTime, System.DateOnly and System.TimeOnly are also being relied on through a dynamic approach.

@roji
Copy link
Member Author

roji commented Jan 3, 2022

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

@smitpatel smitpatel changed the title Add [DynamicDependency] on System.Math for trimming [release/6.0] Add [DynamicDependency] on System.Math for trimming Jan 3, 2022
@ajcvickers ajcvickers added this to the 6.0.x milestone Jan 4, 2022
@leecow leecow modified the milestones: 6.0.x, 6.0.2 Jan 4, 2022
@roji roji merged commit 13bb9b0 into dotnet:release/6.0 Jan 6, 2022
@roji roji deleted the MathDynamicDependency6.0 branch January 6, 2022 16:10
@roji roji linked an issue Jan 6, 2022 that may be closed by this pull request
@ajcvickers ajcvickers removed this from the 6.0.2 milestone Jan 6, 2022
@ajcvickers ajcvickers changed the title [release/6.0] Add [DynamicDependency] on System.Math for trimming [6.0.2] Add [DynamicDependency] on System.Math for trimming Jan 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

When trimming, queries fail because of missing System.Math
5 participants