Skip to the content.

Terminology: factory method is a static method that returns an instance of a type.

Your type has both at least one constructor and at least one factory method marked with [ExplicitConstructor]. Dapper.AOT simply uses the constructor in such a case. Recommended action is to remove the [ExplicitConstructor] attribute from one of the construction mechanisms.

Bad:

class MyType
{
    public int A { get; private set; }
    
    // constructor
    [ExplicitConstructor] 
    public MyType(int a) { A = a; }

    // factory method
    [ExplicitConstructor]
    public static MyType Create(int a) => new MyType { A = a };
}

Good:

class MyType
{
    public int A { get; private set; }
    
    // constructor
    [ExplicitConstructor] 
    public MyType(int a) { A = a; }

    public static MyType Create(int a) => new MyType { A = a };
}

Also Good could be:

class MyType
{
    public int A { get; private set; }
    
    public MyType(int a) { A = a; }

    // factory method
    [ExplicitConstructor]
    public static MyType Create(int a) => new MyType { A = a };
}