Skip to content

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

Closed as duplicate

Description

@jianmingyong

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

Activity

  1. roji commented on Dec 1, 2021

    @roji
    Member

    Duplicate of #26288

  2. roji commented on Dec 1, 2021

    @roji
    Member

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

  3. roji commented on Jan 3, 2022

    @roji
    Member

    @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

Metadata

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