Forum Xamarin.Forms

AutoMapper exception with Linker Behavior = Link Framework SDKs Only

stesvisstesvis USMember ✭✭✭✭

I am using AutoMapper in my app, which works great In Debug mode on my phone, with Linker Behavior = Don't Link.
However, in the AppStore configuration, where the Linker Behavior = Link Framework SDKs Only.

The exception I get is this:

Mapper not initialized. Call Initialize with appropriate configuration. If you are trying to use mapper instances through a container or otherwise, make sure you do not have any calls to the static Mapper.Map methods, and if you're using ProjectTo or UseAsDataSource extension methods, make sure you pass in the appropriate IConfigurationProvider instance.

When I call this:
var user = AutoMapper.Mapper.Map<User>(userDTO);

Is there a workaround? I should not use Don't Link in production, but I don't know how else to fix this.
I am sure I am not the only one using AutoMapper in a XF app?

Thanks!

Best Answer

  • stesvisstesvis USMember ✭✭✭✭
    Accepted Answer

    The problem was in iOS.
    I just found a solution, for those that will have the same issue.

    I added a new file in the iOS project root (but it doesn't have to be the root) called LinkerFix.xml.
    Then I added this content:

    <linker>
      <assembly fullname="mscorlib">
        <type fullname="System.Convert" preserve="All" />
      </assembly>
    </linker>
    

    Then I set the Build Action to LinkDescription and AutoMapper started working again with Linker Behavior = Link Framework SDKs Only

Answers

  • MatthewRMatthewR USMember ✭✭

    Which platform is causing you issues?

  • stesvisstesvis USMember ✭✭✭✭
    Accepted Answer

    The problem was in iOS.
    I just found a solution, for those that will have the same issue.

    I added a new file in the iOS project root (but it doesn't have to be the root) called LinkerFix.xml.
    Then I added this content:

    <linker>
      <assembly fullname="mscorlib">
        <type fullname="System.Convert" preserve="All" />
      </assembly>
    </linker>
    

    Then I set the Build Action to LinkDescription and AutoMapper started working again with Linker Behavior = Link Framework SDKs Only

Sign In or Register to comment.