Skip to content

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

Closed as not planned

Description

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

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

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions