Skip to content

An error occurs when mapping a Dictionary to another Dictionary in HigLabo.Mapper. #117

@yasee

Description

@yasee

Bug Report

Summary

An error occurs when mapping a Dictionary to another Dictionary in HigLabo.Mapper.

Test Code

using HigLabo.Core;

class Program
{
    static void Main(string[] args)
    {
        var d = new Dictionary<int, string>();
        d.Add(100, "Test");
        d.Add(200, "Test2");
        var dto = new Dictionary<int, string>();
        ObjectMapper.Default.Map(d, dto);
    }
}
using HigLabo.Core;

class Program
{
    class Cls1
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }

    class Cls1Dto
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }

    static void Main(string[] args)
    {
        var d = new Dictionary<int, Cls1>();
        d.Add(100, new Cls1 { Id = 100, Name = "Test" });
        d.Add(200, new Cls1 { Id = 200, Name = "Test2" });
        var dto = new Dictionary<int, Cls1Dto>();
        ObjectMapper.Default.Map(d, dto);
    }
}

Error

Unhandled exception. System.InvalidOperationException: No method 'Add' on type 'System.Collections.Generic.Dictionary`2+KeyCollection[System.Int32,System.String]' is compatible with the supplied arguments.
   at System.Linq.Expressions.Expression.FindMethod(Type type, String methodName, Type[] typeArgs, Expression[] args, BindingFlags flags)
   at System.Linq.Expressions.Expression.Call(Expression instance, String methodName, Type[] typeArguments, Expression[] arguments)
   at HigLabo.Core.ObjectMapper.CreateMapCollectionExpression(MapParameter parameter, CompileState state)
   at HigLabo.Core.ObjectMapper.CreateFunctionExpression(Type sourceType, Type targetType)
   at HigLabo.Core.ObjectMapper.CreateMapMethod(Type sourceType, Type targetType)
   at HigLabo.Core.ObjectMapper.Map[TSource,TTarget](TSource source, TTarget target)
   at Program.Main(String[] args) in /path/to/projects/higmlabo_mapper_test/SimpleApp/Program.cs:line 11

version

HigLabo.Mapper: 2.2.0.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions