1

We use AutoMapper in Xamarin.Forms iOS projects and don't have any issues with Azure DevOps release builds, but when trying the same in .NET MAUI iOS we get the above error with a simple map:

var bla = mapper.Map<Class2>(new Class1());

This is with a release config build on Azure DevOps deployed to TestFlight. I haven't been able to replicate this locally at all.

Any suggestion or pointers? Is there anything I can do to force Automapper to not use reflection?

5
  • Probably github.com/dotnet/runtime/issues/79354. They'll include the fix in a service release. Commented Dec 24, 2022 at 19:27
  • @LucianBargaoanu I saw that issue but I don't think this is related. The example classes above don't have IEnumerable, and the error is different. Commented Dec 24, 2022 at 20:33
  • I'd bet it's the same. Anyway, AM has little to do with your error. Commented Dec 25, 2022 at 6:07
  • 1
    Have a try to enable Interpreter and see if it works. Commented Dec 26, 2022 at 7:25
  • What kind of agent do you use to run pipeline Microsoft-hosted agent or self-hosted agent? You can run it in self-hosted and see whether it works or not. Commented Dec 29, 2022 at 7:47

1 Answer 1

3

On iOS, you must have the interpreter enabled to be able to use reflection. On Debug, the interpreter is enabled by default, that's why you cannot reproduce it locally. On release, it's disabled by default.

You can fix this by making sure the interpreter is enabled in both Debug and Release configs, by adding this to your .csproj:

<PropertyGroup Condition="$(TargetFramework.Contains('-ios'))">
    <UseInterpreter>true</UseInterpreter> 
</PropertyGroup>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.