I am working on a Xamarin project that is using AutoMapper. When linking is set to "Link Framework SDKs Only" I get the following error when initializing the maps
System.ArgumentNullException: Value cannot be null. Parameter name: method
The exception is not much to go on and neither is the callstack
AutoMapper.Mappers.ConvertMapper.MapExpression
AutoMapper.Execution.TypeMapPlanBuilder.ObjectMapperExpression
AutoMapper.Execution.TypeMapPlanBuilder.MapExpression
AutoMapper.Mappers.NullableSourceMapper.MapExpression
AutoMapper.Execution.TypeMapPlanBuilder.ObjectMapperExpression
AutoMapper.Execution.TypeMapPlanBuilder.MapExpression
AutoMapper.Execution.TypeMapPlanBuilder.MapExpression
AutoMapper.Execution.TypeMapPlanBuilder.CreatePropertyMapFunc
AutoMapper.Execution.TypeMapPlanBuilder.CreatePropertyMapFunc
AutoMapper.Execution.TypeMapPlanBuilder.TryPropertyMap
AutoMapper.Execution.TypeMapPlanBuilder.CreateAssignmentFunc
AutoMapper.Execution.TypeMapPlanBuilder.CreateMapperLambda
AutoMapper.TypeMap.Seal AutoMapper.MapperConfiguration.Seal
AutoMapper.MapperConfiguration..ctor
AutoMapper.MapperConfiguration..ctor AutoMapper.Mapper.Initialize
The initial reading of that suggests that the Linker is simply removing some properties or indeed methods from some class we are using.
However, after commenting out most of the mappings and then reintroducing them one at a time I find that this class is currently causing the error.
[Preserve]
internal class ItemBase : CareRecordItemBase
{
[Preserve]
public string Topic { get; set; }
[Preserve]
public string InPractice { get; set; }
[Preserve]
public string PrivateVal { get; set; }
}
If I comment out the InPractice
property the exception does not get thrown. This makes no sense to me. Can anyone explain why this might be a problem?
Are there better ways of diagnosing these issues?
See comment from AutoMapper author Lucian Bargaoanu. I needed to include an xml file that adds configuration to the Linking process.
Lucian refers to this Automapper Issue, https://github.com/AutoMapper/AutoMapper/issues/2272
Also see