I have an issue where my mapping for a List to Dictionary won't map the Name to the Key property. The Value does fine. The implementation is below. System.ArgumentNullException: 'Value cannot be null. Parameter name: key'
Implementation
_mapper.Map<List<MetaModel>, Dictionary<string, object>>(model.MemberPaymentVendor.Meta)
Config
config.NewConfig<MetaModel, KeyValuePair<string, object>>()
.ConstructUsing(x => new KeyValuePair<string, object>(x.Name, x.Value));
config.NewConfig<List<MetaModel>, Dictionary<string, object>>()
.MapWith(s => ToDictionary<MetaModel>(s));
public static Dictionary<string, object> ToDictionary<T>(List<T> source)
{
if (source == null)
return new Dictionary<string, object>();
return source.Select(v => v.Adapt<KeyValuePair<string, object>>()).ToDictionary(k => k.Key, v => v.Value);
}