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

When looking up methods via reflection, be trimming/AOT-friendly #26288

Open
1 of 2 tasks
Tracked by #21894
roji opened this issue Oct 8, 2021 · 10 comments · Fixed by #27099
Open
1 of 2 tasks
Tracked by #21894

When looking up methods via reflection, be trimming/AOT-friendly #26288

roji opened this issue Oct 8, 2021 · 10 comments · Fixed by #27099
Assignees
Labels
area-aot area-global consider-for-current-release punted-for-7.0 Originally planned for the EF Core 7.0 (EF7) release, but moved out due to resource constraints. type-enhancement
Milestone

Comments

@roji
Copy link
Member

roji commented Oct 8, 2021

@0xced
Copy link
Contributor

0xced commented Nov 18, 2021

I just got this exception when executing a self-contained, trimmed executable with EF Core 6.0.0:

System.TypeInitializationException: The type initializer for 'Microsoft.EntityFrameworkCore.SqlServer.Query.Internal.SqlServerMathTranslator' threw an exception.
---> System.InvalidOperationException: Could not find method 'Ceiling' on type 'System.Math'
at System.SharedTypeExtensions.GetRequiredRuntimeMethod(Type type, String name, Type[] parameters)
at Microsoft.EntityFrameworkCore.SqlServer.Query.Internal.SqlServerMathTranslator..cctor()

I quickly realized it was because of trimming and I had to disable it.

I see you explicitly mention GetRequiredRuntimeMethod which appears in this stack trace so I'm looking forward to a trimming friendly version of EF Core. 😉

@roji
Copy link
Member Author

roji commented Nov 18, 2021

@0xced yeah, this is one of the high-priority items for EF7 - stay tuned, it'll hopefully make it into an early preview.

@seriouz
Copy link

seriouz commented Dec 13, 2021

We ran in this issue, too when switching to .NET6 / EF6 with trimmed binaries on production systems (Docker Images).
Very annoying, now the builds can't be trimmed anymore 😢

@roji
Copy link
Member Author

roji commented Dec 28, 2021

For a workaround with EF Core 6, see this (thanks @EjaYF).

@lechgu
Copy link

lechgu commented Dec 31, 2021

verified, workaround fixes the issue for my scenario, thanks @EjaYF, @roji.
Will this be officially fixed in .net 6?

@roji
Copy link
Member Author

roji commented Dec 31, 2021

This issue is in the 7.0.0 milestone. There's little chance we'll be fixing this in 6.0.0, but we'll discuss that after the fix is done and the general trimming situation is clearer.

@seriouz
Copy link

seriouz commented Jan 2, 2022

EF6 is LTS so people will use it until 8. November 2024. In my opinion the trimming fix should be made in EF6 when it will be supported for such a long time.

@roji
Copy link
Member Author

roji commented Jan 2, 2022

@seriouz @lechgu @EjaYF if someone can share a minimal, trimmed console application which works with EF Core 5.0 (i.e. executes some trivial query), that would help push this forward. I'm seeing various linker-related failures when doing that, since EF Core 5.0 (and 6.0) weren't annotated for trimming in any way.

@roji
Copy link
Member Author

roji commented Jan 3, 2022

Never mind, I've managed to get a trimmed version working here. I'll update soon.

@roji
Copy link
Member Author

roji commented Jan 6, 2022

FYI I've merged #27098 for 6.0.2 - that's a temporary fix which specifically fixes the Math-related errors; in my testing it allowed at least basic queries to run properly in trimmed applications. This isn't a guarantee that everything will work - just an attempt to unblock people for basic usage. I'm tackling trimming in a more serious way for 7.0, please report any further problems you run across.

@ajcvickers ajcvickers reopened this Feb 14, 2022
@ajcvickers ajcvickers removed this from the 7.0.0 milestone Feb 14, 2022
@AndriySvyryd AndriySvyryd added this to the 7.0.0 milestone Feb 15, 2022
@ajcvickers ajcvickers added the punted-for-7.0 Originally planned for the EF Core 7.0 (EF7) release, but moved out due to resource constraints. label Sep 16, 2022
@ajcvickers ajcvickers modified the milestones: 7.0.0, Backlog Sep 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-aot area-global consider-for-current-release punted-for-7.0 Originally planned for the EF Core 7.0 (EF7) release, but moved out due to resource constraints. type-enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants