Skip to content

ArgumentException : Cannot bind to the target method because its signature is not compatible with that of the delegate type. #702

@malibay81

Description

@malibay81

Dear Support,

following exception occurs when auto mapping a model with viewmodel with same methods but different parameters !

System.ArgumentException
  HResult=0x80070057
  Message=Cannot bind to the target method because its signature is not compatible with that of the delegate type.
  Source=System.Private.CoreLib
  StackTrace:
   at System.Reflection.RuntimeMethodInfo.CreateDelegateInternal(Type delegateType, Object firstArgument, DelegateBindingFlags bindingFlags)
   at System.Reflection.RuntimeMethodInfo.CreateDelegate(Type delegateType)
   at ServiceStack.AssignmentMember.CreateGetter() in C:\BuildAgent\work\912418dcce86a188\src\ServiceStack.Text\AutoMappingUtils.cs:line 1085
   at ServiceStack.AssignmentEntry..ctor(String name, AssignmentMember from, AssignmentMember to) in C:\BuildAgent\work\912418dcce86a188\src\ServiceStack.Text\AutoMappingUtils.cs:line 1048
   at ServiceStack.AssignmentDefinition.AddMatch(String name, AssignmentMember readMember, AssignmentMember writeMember) in C:\BuildAgent\work\912418dcce86a188\src\ServiceStack.Text\AutoMappingUtils.cs:line 1140
   at ServiceStack.AutoMappingUtils.<>c__DisplayClass27_0.<GetAssignmentDefinition>b__0(String <p0>) in C:\BuildAgent\work\912418dcce86a188\src\ServiceStack.Text\AutoMappingUtils.cs:line 457
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at ServiceStack.AutoMappingUtils.GetAssignmentDefinition(Type toType, Type fromType) in C:\BuildAgent\work\912418dcce86a188\src\ServiceStack.Text\AutoMappingUtils.cs:line 445
   at ServiceStack.AutoMappingUtils.PopulateFromPropertiesWithoutAttribute[To,From](To to, From from, Type attributeType) in C:\BuildAgent\work\912418dcce86a188\src\ServiceStack.Text\AutoMappingUtils.cs:line 598
   at UnitTests.AutoMapperTest.Test_PopulateFromPropertiesWithoutAttribute() in K:\Library II\4. VB\09 Tests\UnitTests\AutoMapperTest.cs:line 37

This is the test code I have created:

   [TestClass]
   public class AutoMapperTest
   {
      [TestMethod]
      public void Test_PopulateFromPropertiesWithoutAttribute  ()
      {
         MyModel     myModel     = new MyModel ();
         MyViewModel myViewModel = new MyViewModel ();
         myViewModel.MyProp = "Test";
         myModel.PopulateFromPropertiesWithoutAttribute (myViewModel, typeof(IgnoreOnPopulateAttribute));
         Assert.AreEqual (myModel.MyProp, myViewModel.MyProp);
      }

      class MyModel
      {
         public void MyMethode (string myProp)
         {
            MyProp = myProp;
         }

         public string MyProp { get; set; }
      }

      class MyViewModel
      {
         public void MyMethode ()
         {
            MyProp = "MyMethode";
         }

         public string MyProp { get; set; }
      }
   }

Please see also the attached gif for more information.

AutoMapperArgumentException

Could you verify and fix it please.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions