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

[.NET 6] Migrate API - Could not find method 'AddYears' on type 'System.DateOnly' #26860

Closed
jianmingyong opened this issue Dec 1, 2021 · 3 comments

Comments

@jianmingyong
Copy link

If users were to use the trimming option in .NET 6, one might face this exception if they used Migrate() or MigrateAsync() API.

Could not find method 'AddYears' on type 'System.DateOnly' at System.SharedTypeExtensions.GetRequiredRuntimeMethod(Type type, String name, Type[] parameters)

For now, it can be workaround with adding a line of code (preferably in main class) or using rd.xml

/// <summary>
/// FIXME: This is required for EF Core 6.0 as it is not compatible with trimming.
/// </summary>
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
private static Type _keepDateOnly = typeof(DateOnly);

Include provider and version information

EF Core version: 6.0.0
Database provider: Microsoft.EntityFrameworkCore.Sqlite
Target framework: .NET 6.0
Operating system: Windows 10
IDE: Visual Studio 2022

#26383 #21894

@roji
Copy link
Member

roji commented Dec 1, 2021

Duplicate of #26288

@roji roji marked this as a duplicate of #26288 Dec 1, 2021
@roji
Copy link
Member

roji commented Dec 1, 2021

#26288 tracks making all reflection-based method lookup compatible with trimming (rather than having an issue for each method).

@roji
Copy link
Member

roji commented Jan 3, 2022

@jianmingyong I've started to look into this, could you please post a full stack trace of the exception you got with AddYears? I'm specifically interested since that exception was triggered from Migrate.

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

No branches or pull requests

3 participants