Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin iOS Linker causing AutoMapper issues

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?

like image 978
Pat Long - Munkii Yebee Avatar asked Jan 03 '23 05:01

Pat Long - Munkii Yebee


1 Answers

Based on Pat's Answer:

  1. Add an XML file LinkDescription.xml, you can name it anything you want.
  2. Add this code:
<linker> 
    <assembly fullname="mscorlib">
        <type fullname="System.Convert" preserve="All" />
    </assembly>
</linker>
  1. Set the file's build action to LinkDescription
like image 184
Iain Smith Avatar answered Jan 12 '23 14:01

Iain Smith