Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
    hey, are you referring to the Map(s, d, context) method? because it works fine in my case
    Steven Liekens
    me? no
    @StevenLiekens , you are correct thanks for correctng me
    Steven Liekens
    np thanks for trying to help
    Pablo Montilla
    Hello there, I'm not sure if this warrants an issue post or if I just need to characterize better my problem. I'm getting a NullRef on SourceToDestinationNameMapperAttributesMember.cs sometimes while running my code. I you see line 18, when array.Length == 0 line 20 will always throw...any ideas how I can fix this problem?
    Brian Donahue
    I'm trying to map a dynamic/ExpandoObject to a class of mine, and seeing some behavior I don't understand. When I use CreateMissingTypeMaps it executes the mapping, but crashes because there are some mismatched types (string > decimal, etc). I need to do some custom mapping. So I tried to create my own maps using CreateMap<dynamic, MyType>() or CreateMap<ExpandoObject, MyType>() but those didn't work. The Map call returns an empty object (default values). Is this possible? Next step is to try converting the ExpandoObject to IDictionary<string, object> and create a custom mapping for that.
    Alexander Carls

    I am trying to debug why my AutoMapper map, does not leverage joins with EF Core. I created a slim down query

            await db
              .Select(m => new Move {
                Id = m.Id,
                CommandSegments = m.CommandSegments.Select(c => c.Segment),
                Notes = m.Notes.Select(n => n.Text)

    This results in three queries for Moves, Notes and CommandSegments, while I would rather have just one.
    Doesn anyone have an idea why? I am using the Postgres adapter.

    Question -Does the mapper work using reflection every map call? or are you compiling IL code at run time for each mapping profile to make the performance better?
    Hi All, I am getting "Value cannot be null. Parameter name: querySource" exception when try to use Automapper
    It is coming from this member mapping
    .ForMember(p => p.Region, opt => opt.MapFrom(p => p.RegAddress.Country.Region != null ? p.RegAddress.Country.Region : p.Nationality.Region))
    If I use only one mapping without using conditional mapping, it is working
    for e.g. .ForMember(p => p.Region, opt => opt.MapFrom(p => p.Nationality.Region)) or .ForMember(p => p.Region, opt => opt.MapFrom(p => p.RegAddress.Country.Region )) working without any issue
    Are you trying to map or project an IQueryable? Can you provide the code of the call ?
    @JonLopezGarcia I am trying to Project from IQueryable
    var pendingRegs = _worker.Repository<UserRegistration>().All.Where(q => q.Status.Name == UserRegistrationStatus.Pending).ProjectTo<PendingClientModel>().ToList();
    Kevin Sigmund
    Hi, I'm having an issue when trying to configure a test that uses a value resolver:
    AutoMapper.Mapper.Initialize(cfg =>
                    var config = Substitute.For<IConfiguration>();
                    cfg.ConstructServicesUsing(c => new ProductImagePathResolver(config));
    But for some reason, AutoMapper is trying to map the resolver: System.InvalidCastException : Unable to cast object of type 'Newgistics.Fulfillment.AutoStore.Synq.Client.Mappings.ProductImagePathResolver' to type 'Newgistics.Fulfillment.AutoStore.Common.Mappings.NullableValueResolver'.
    Kevin Sigmund
    I ended up just using constructor-injection into the Profile and then passing that into the Resolver there. Still, not sure why I'm seeing the behavior I described.
    Maxime Dubois
    how can I create mapping for the source being a serialized json array to a destination of a list of an object?
    Shayne van Asperen
    @maximedubois Mapper.CreateMap<string, List<MyObject>>() with your own custom value resolver
    Victorio Berra
    Is there a way to specify a global base map without having to include every time?
    For example, I have IAuditable and IAuditableViewModel. Some of my viewmodels have it, some dont. In my profiles I am having to Include<IAuditable, IAuditableViewModel>()every time
    I have two models, one has a List<Guid> collection and one has a List<Dto> collection. When mapping I'd like to resolve those Guids to Dtos but IValueResolver doesn't support async which I need to call certain methods to resolve the objects, how can I accomplish this with AutoMapper?
    Thanks! :)
    Victorio Berra
    ForAllMaps is not running for me. I put throw new NotImplemenetEx... My assert config blows up before that throw ever happens. Shouldnt all profiles be loaded before this happens?
    Looks like order matters. If I put ForAllMaprs directly on the config in AddAutoMapper it works.
    Teo Chai Huat
    Hi All, not sure what I did wrong, my nullable object always reset to default value. how do I configure automapper to ignore/skip null object?

    Guys I need some help.

    I want to set a destination object to null if certain properties in the source are not present. How would that look?


    Another question - is it possible to use AutoMapper to convert another member if it is a subproperty of another mapping?

    Source_2 has a property called Destination_1


    CreateMap<Source_1, Destination_1>();
    CreateMap<Source_2, Destination_2>()
       .ForMember(d => d.Destination_1, o => o.MapFrom(s => map into <Destination_1> using the first mapping));
    Jack Herring
    Unsure if it is bad etiquette here to post links to SO questions but I am stuck and in need of help! https://stackoverflow.com/questions/56258652/automapper-global-configuration-convert-null-array-property-to-empty-array-by does anyone know how to configure default array conversion behaviour when the source array is null? AutoMapper is exploding because int[] doesn't have a no-arg ctor
    Bob Meijwaard
    Mapper.Initialize(cfg => { cfg.AddProfile<CoreProfile>(); }); So as I just updated to v8.1.1 and VS now tells me that the static API is obsolute and that I have to use DI. Why? I don't want that, please do not obsolute the static API.
    You should do the following:
    var cfg = new MapperConfigurationExpression();
    cfg.CreateMap<Domain.Entities.OrderRoot, IApp.DTO.OrderRoot>();
    @DinoSourcesRex, if I understand you requirement propertly then you may try something like this
    cfg.CreateMap<Source1, Destination1>();
    cfg.CreateMap<Source2, Destination1>()
          .IncludeMembers(x => x.PropOfSource1Type);
    class Source2
      Source1 PropOfSource1Type {get; set;}
      //… other props
    I've encountered an issue which seems to have been raised previously (AutoMapper/AutoMapper#2745) but with no resolution, and the workaround mentioned has a flaw when the destination object has more than one constructor.
    I've looked at the source code in order to type to identify a solution, but it seems that during the MapDestinationCtorToSource method, the only access to the ForCtor methods in via:
    options._typeMapConfigs[].CtorParamConfigurations[], but due to the generic abstraction layers involved, I can't fathom how to do the checking required.
    Any assistance would be appreciated...
    James Webster
    Is it possible to customise the mapping of a class -> ExpandoObject? I have an IEnumerable<SomeClass> that I can map to IEnumerable<ExpandoObject> just fine, but I want to explictly override some of the dynamically generated mapping, (e.g. some properties on SomeClass should be given a different name on the ExpandoObject, some should have their type converted, but most of them should be mapped automatically).
    If I just call _mapper.Map<IEnumerable<ExpandoObject>>(anEnumerableOfMyClass) then everything is mapped onto the enumerable of ExpandoObject.
    James Webster
    If I configure a map via CreateMap<SomeClass, ExpandoObject>() then I get a list of empty ExpandoObjects. Is there a way to tell CreateMap to do the default mapping (I have tried various combinations of .ForAllMembers() but there doesn't appear to be a way to say - just do the default behaviour... which I would then override with .ForMember()
    James Webster
    I think the problem I have here is that mapping is generally focused on the members of the destination. In this case, the destination has no explicit members. But there doesn't seem to be a way to override the default behaviour when mapping TO dynamic.
    Hello there, Are there anyone who know what encoding type of test code files(AutoMapper.UnitTests.Internationalization.When_mapping_a_source_with_non_english_property_names, AutoMapper.UnitTests.Tests.StubNamingConvention)? I couldn't build and test automapper solution, My jetbrains rider can't recognize encoding type of this file.
    Osama AbuSitta
    hello there , I am download automapper source code and trying to build it ,
    when run the psake.cmd I got this error "C:\Users\o.abusitta.nuget\packages\microsoft.dotnet.apicompat\1.0.0-beta.19423.1\build\Microsoft.DotNet.ApiCompat.targets(96,5): error : ApiCompat failed for 'D:\AutoMapper-master\AutoMapper-master\src\AutoMapper\bin\Debug\netstandard2.0\AutoMapper.dll' [D:\AutoMapper-master\AutoMapper-master\src\AutoMapper\AutoMapper.csproj]"
    and when I build it i got "Error ApiCompat failed for '"
    There is any guideline to build the solution
    Osama AbuSitta
    Edward Lichtman
    I'm looking for a "<Any,Any>" method of mapping. I can't seem to find one and was wondering if there is a "best-practices" reason there isn't one, and does anyone have a workaround like a "CatchAllMapper" implementation?
    Sander Geerts

    Hi all, how would I configure Automapper in a Profile to do a mapping which changes the object struture? e.g.:


    Should Become

            List<ChildObject> // ChildObject A and B
            List<ChildObject> // ChildObject C
    this.CreateMap<Data.Task.Task, POCO.Task>() .ForMember(d => d.User, o => o.MapFrom(m => m.UserTaskAssignment.FirstOrDefault().User.Name))
    I am using automapper to map my data object to poco. User property is not being populated even though I added mapping. Rest of the map works.
    I tried .AfterMap((o,d) => d.User = o.UserTaskAssignment.FirstOrDefault()?.User.Name); as well. Did not work.