xamarin / xamarin-macios

.NET for iOS, Mac Catalyst, macOS, and tvOS provide open-source bindings of the Apple SDKs for use with .NET managed languages such as C#
Other
2.42k stars 507 forks source link

[iOS] Attempting to JIT compile method while running in aot-only mode when using AutoMapper on iOS with .NET 8 #20611

Closed thomaschenato closed 1 month ago

thomaschenato commented 1 month ago

Hello,

I'm working on a Xamarin.iOS migration to .NET 8. However encounter a runtime crash "JIT compile method while running in aot-only mode"

I've read up a few past issues / articles around JIT/AOT crashes in Xamarin / Xamarin.Form and the workaround solution in the past e.g.

https://github.com/xamarin/xamarin-macios/issues/15681

<PropertyGroup>
    <UseInterpreter>true</UseInterpreter>
</PropertyGroup>

However this workaround doesn't seem to work in .NET 8 as it trigger a crash at app launching.

Please see the detail below and wonder if there is fix in .NET 8 with AutoMapper on iOS

Steps to Reproduce

  1. Create an basica iOS project targeting .NET 8 from template
  2. With AutoMapper 13.0.1, .NET 8 SDK 8.0.203, XCode 15.1
  3. TargetObject targetObject = mapper.Map<TargetObject>(info);
  4. iOS throw exception during runtime on both simulator or physical iPhone. Exception detail listed in the Actual Behaviour section

Expected Behavior

Target object can be created

Actual Behavior

System.ExecutionEngineException: Attempting to JIT compile method '(wrapper dynamic-method) mapper_ios.AppDelegate/TargetObject object:Thunk1ret_TargetObject_Object_TargetObject_ResolutionContext (System.Func`2<object[], object>,object,mapper_ios.AppDelegate/TargetObject,AutoMapper.ResolutionContext)' while running in aot-only mode. See https://docs.microsoft.com/xamarin/ios/internals/limitations for more information.

Environment

Version information ``` macOS Sonoma 14.1 XCode 15.1 .NET 8 SDK 8.0.203 ```

Build Logs

Example Project (If Possible)

rolfbjarne commented 1 month ago

Please provide a complete test project we can use to reproduce the problem, that way we can be sure we're testing the same thing.

microsoft-github-policy-service[bot] commented 1 month ago

Hi @thomaschenato. We have added the "need-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/xamarin/xamarin-macios/blob/main/docs/bug-repro.md This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

microsoft-github-policy-service[bot] commented 1 month ago

Hi @thomaschenato. Due to inactivity, we will be closing this issue. Please feel free to re-open this issue if the issue persists. For enhanced visibility, if over 7 days have passed, please open a new issue and link this issue there. Thank you.