Skip to content

.Ignore() for interface pairs throws ArgumentException #723

Description

@luczito

Suppose we have two interfaces which are identical except that one has a field the other does not.

public interface Interface1
{
    public string Inter { get; set; }
    
    public string Ignore { get; }
}
public interface Interface2
{
    public string Inter { get; set; }
}

When creating a mapping config we would simply ignore this field as:

config.NewConfig<Interface1, Interface2>() 
   .TwoWays()
   .Ignore(dest => dest.Ignore);

However this throws the error:
"System.ArgumentException : Incorrect number of arguments for constructor"

The only fix as far as i can tell is to explicitly map this property to something E.G:

string temp = null;
config.NewConfig<Interface1, Interface2>()
   .TwoWays()
   .Map(dest => dest.Ignore, src => temp);

Or to hardcode what class to use when this mapping pair is hit:

config.NewConfig<Interface1, Interface2>()
   .Twoways()
   .ConstructUsing(src => new DerivedClass());

Both of these fixes are suboptimal, are there any other way to get around this issue?

Activity

  1. DocSvartz commented on Jan 5, 2025

    @DocSvartz
    Contributor

    Hello @luczito I think I found the place where this error occurs.
    But are you sure about the specified configuration or the description of the interfaces provided?
    On this basis, I can set the condition you specified only in the reverse configuration.

      TypeAdapterConfig<Interface2, Interface1>
          .NewConfig()
          .TwoWays()
          .Ignore(dest => dest.Ignore);
    

    (And it doesn't make much sense. Since the value won't be transferred anyway. If this field is not in the source).

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