Ashley Kilgour
Ashley Kilgour

Reputation: 1258

Cant Create Automapper custom value resolver

I have been trying to create a automapper Custom value resolvers, but I seem to have missed some set up step as it can never seem to find

 public abstract class ValueResolver<TSource, TDestination> : IValueResolver

So in the following snippet will not compile.

using DITest.Models; // This is where the SalesOrder class is
using AutoMapper;

namespace DITest.AutoMapper.SaleOrder
{
  public class FullAddress : ValueResolver<SalesOrder, string>
  {
    protected override string ResolveCore(SalesOrder source)
    {
        return "foo bar"; 
    }
  }
}

I get the error message

The type or namespace name 'ValueResolver<,>' could not be found (are you missing a using directive or an assembly reference?)

Its say the using AutoMapper is not used.

In the past I have been naughty and hacked in a reference for lib\net45\AutoMapper.dll

Upvotes: 4

Views: 2330

Answers (2)

Lucian Bargaoanu
Lucian Bargaoanu

Reputation: 3516

ValueResolver is gone. IValueResolver is the replacement. And there is also IMemberValueResolver, as the docs say.

Upvotes: 1

user8384758
user8384758

Reputation: 21

Please try IMemberValueResolver type instead of IValueResolver. The AutoMapper had some upgraded things.

https://github.com/AutoMapper/AutoMapper/wiki/5.0-Upgrade-Guide

Upvotes: 2

Related Questions