Missing type map configuration or unsupported mapping

7,645 views
Skip to first unread message

Aftab Quraishi

unread,
Aug 26, 2013, 11:14:00 AM8/26/13
to automapp...@googlegroups.com
Hi all,

I am getting this error "Missing type map configuration or unsupported mapping" after every time my app restarts. After rebuilding the solution it works fine again. I tried unit testing with Mapper.AssertConfigurationIsValid() as mentioned in https://github.com/AutoMapper/AutoMapper/wiki/Configuration-validation. I found a validation error and I fixed it using options.Ignore(). Then the test passed with all configurations. But the problem still persisted as is. Then, I commented out all mappings but kept only one to troubleshoot the issue. Still getting the same error. I am not getting any other ideas to try out.

I am using microsoftnlayerapp.codeplex.com with .Net 4.0, AutoMapper 2.2.1, MVC 3.0, EF 4.3.1. My app is almost half way done, and i dint face any other significant issues.

Please help. Also, please let me know if I should provide here any other details to help identify the issue.

My sincere thanks.

Jimmy Bogard

unread,
Aug 26, 2013, 1:28:41 PM8/26/13
to automapper-users
Where is your configuration, and what kind of app is this? Web app?


--
You received this message because you are subscribed to the Google Groups "AutoMapper-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to automapper-use...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Aftab Quraishi

unread,
Aug 29, 2013, 10:57:05 AM8/29/13
to automapp...@googlegroups.com
Hi Jimmy,

Thanks a lot for your response!

My app is basically a four layered app -

1. Presentation (Web/MVC)
2. Application (AutoMapper DTO profile and DTOs, App Services)
3. Domain
4. Infrastructure/Data (EF)

There is also a Infrastructure/Cross-Cutting layer with DTO Adapter (Automapper), DI container (Unity) etc.

(Please visit the codebase from http://microsoftnlayerapp.codeplex.com/SourceControl/latest to get a complete idea of my app's structure.)

I hope the following details will be helpful.

In my MVC Web app I am consuming the DTOs, which are configured and supplied by the Application layer. The configuration in Application layer is similar to the following -

using AutoMapper;

class PublicPortalModuleProfile : Profile
{
    protected override void Configure()
    {
        var cityMappingExpression = Mapper.CreateMap<Restaurant, RestaurantDTO>();
    }
}

And then mapped like this:

public RestaurantDTO GetRestaurantDetail(Guid restaurantId)
{
    var restaurant = _restaurantRepository.GetRestaurantByRestaurantId(restaurantId);

    return restaurant.ProjectedAs<RestaurantDTO>();
}

public static TProjection ProjectedAs<TProjection>(this Entity item)
            where TProjection : class,new()
{
    //TypeAdapterFactory uses AutomapperTypeAdapterFactory (configured/injected using Unity, shown later
    //and calls the Create() method which returns AutomapperTypeAdapter here
    var adapter = TypeAdapterFactory.CreateAdapter(); 
    return adapter.Adapt<TProjection>(item);
}


In the Infrastructure/Cross-Cutting layer:

In AutomapperTypeAdapterFactory class:

public AutomapperTypeAdapterFactory()
{
    //scan all assemblies finding Automapper Profile
    var profiles = AppDomain.CurrentDomain
                                    .GetAssemblies()
                                    .SelectMany(a => a.GetTypes())
                                    .Where(t => t.BaseType == typeof(Profile));

    Mapper.Initialize(cfg =>
    {
        foreach (var item in profiles)
        {
            if (item.FullName != "AutoMapper.SelfProfiler`2")
                cfg.AddProfile(Activator.CreateInstance(item) as Profile);
        } 
    });
}

public ITypeAdapter Create()
{
    return new AutomapperTypeAdapter();
}

In AutomapperTypeAdapter class:

public TTarget Adapt<TTarget>(object source) where TTarget : class, new()
{
    return Mapper.Map<TTarget>(source);  // Error in this line
}

In Unity I have the following configurations -

container.RegisterType<ITypeAdapterFactory, AutomapperTypeAdapterFactory>(new ContainerControlledLifetimeManager());

var typeAdapterFactory = container.Resolve<ITypeAdapterFactory>();
TypeAdapterFactory.SetCurrent(typeAdapterFactory);


The complete error detail is as follows:

Missing type map configuration or unsupported mapping.

Mapping types:
Restaurant_DD4DBDDB13217B3C5A757FACC3ADBFF7FFBCE0547A6080879A4366BD1D0B08D8 -> RestaurantDTO
System.Data.Entity.DynamicProxies.Restaurant_DD4DBDDB13217B3C5A757FACC3ADBFF7FFBCE0547A6080879A4366BD1D0B08D8 -> 

DhakaFoodies.Application.MainBoundedContext.DTO.RestaurantDTO

Destination path:
RestaurantDTO

Source value:
System.Data.Entity.DynamicProxies.Restaurant_DD4DBDDB13217B3C5A757FACC3ADBFF7FFBCE0547A6080879A4366BD1D0B08D8

Again, thanks for all your time and support. Keep up the great works.

Aftab.

Jimmy Bogard

unread,
Aug 29, 2013, 2:00:16 PM8/29/13
to automapper-users
Will your DTO's actually populate that change tracking stuff? I thought EF only did that through proxies etc.

And at that point, there's no need to communicate that back to the clients. Why not just expose your EF objects directly at that point?


--

Aftab Quraishi

unread,
Sep 4, 2013, 11:10:04 AM9/4/13
to automapp...@googlegroups.com
I dont know exactly how to try "expose your EF objects directly at that point". I tried different solutions including disabling dynamic proxies/lazy loading etc. Nothing worked. 

Finally, I saw a post with EF dynamic proxies DTO mapping problem (http://stackoverflow.com/questions/3441916/automapper-mapping-issue-with-inheritance-and-abstract-base-class-on-collectio) and was able to solve part of my problem. I used DynamicMap method (Mapper.DynamicMap<TTarget>(source)) and got rid of the "Missing type map configuration..." error and mapping working fine with dynamic proxy classes. But now another issue - the DynamicMap method is not able to map list/collection types. When a list is passed to DynamicMap method, its not returning any result (not throwing any error too).

I saw your reply in http://stackoverflow.com/questions/5975240/automapper-failing-to-map-a-simple-list and feel like i am stuck again. Please help.

Jimmy Bogard

unread,
Sep 4, 2013, 11:54:06 AM9/4/13
to automapper-users
Expose directly as in - don't create DTOs. It sounds like what you *really* want is cloning of objects, if your source and destination types look *exactly the same*. Am I wrong here?


--

Aftab Quraishi

unread,
Sep 5, 2013, 9:20:34 AM9/5/13
to automapp...@googlegroups.com
I need to use DTOs and just want to pass data to the presentation layer.

It seems the problem is not with dynamic proxies. I disabled dynamic proxy creation in EF. And tried to use Mapper.Map() method. Now getting the following error -

Missing type map configuration or unsupported mapping.

Mapping types:
Restaurant -> RestaurantDTO
DhakaFoodies.Domain.MainBoundedContext.PublicPortalModule.Aggregates.RestaurantAgg.Restaurant -> DhakaFoodies.Application.MainBoundedContext.DTO.RestaurantDTO

Destination path:
RestaurantDTO

Source value:
DhakaFoodies.Domain.MainBoundedContext.PublicPortalModule.Aggregates.RestaurantAgg.Restaurant

See here, Restaurant -> RestaurantDTO mapping is not working, but surprisingly after rebuilding the solution it works again! Any Idea?


sha...@gmail.com

unread,
Sep 2, 2015, 5:33:44 AM9/2/15
to AutoMapper-users
Follow the given link. It will solve your problem:


Regards,
Shazia.
Reply all
Reply to author
Forward
0 new messages