-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generics Serialization using Json.NET throws "Attempting to JIT compile method '(wrapper delegate-invoke)' while running in aot-only mode" in signed release build iOS-applications #8122
Comments
Ah I see, it does work in debug. Seems that maybe Newtonsoft.Json isn't linker safe? |
This comment was marked as outdated.
This comment was marked as outdated.
First off, love your Channel. Second, I have this or a similar issue on MAUI Mac. Full crash, doesn't even get caught in Try Catch for whatever reason. See the following Log.
|
We're experiencing a similar issues with Json (Newtonsoft) encoding as well. |
Experiencing the same issue. It works fine in the iOS simulator but fails when running on an iOS device. |
@rolfbjarne or @steveisok is this an AOT issue? Thoughts? |
From the stack trace, it looks like it's trying to generate code a runtime, which is not a supported thing in AOT. My recommendation is to enable the interpreter and see if that fixes the problem. |
The workaround by enabling interpreter does fix the issue. As the deserialization example is an generic one, i thought, it may be an AOT issue or issue with JSON.NET library. With System.Text.Json it seems to work without any workarounds |
Im having the exact same issue it works on the next cases, the issue is just happening on Release signed build. | ✅ | iOS Simulator Debug If you want to make it work you can simple add this into your csproj <UseInterpreter Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios' And '$(Configuration)' == 'Release'">true</UseInterpreter> not sure if this can impact sending the build to be distributed to the Store/TestFlight maybe someone from Microsoft can confirm @rolfbjarne @dalexsoto any thoughts? |
@AlejandroRuiz that should work fine when published to the App Store. However, I'd recommend enabling the interpreter for all builds, not just Release builds, that way you test & debug what you're going to ship. |
I am going to close this as the issue is mainly with json.net, however it may be a case that there is some use case in there that iOS is supposed to support but for some reason the code path is not going there. I do know the iOS team has done a bunch of work to hide the iOS limitations. @rolfbjarne should we move this to macios? Or is this outside the bounds of the SDK at this point? |
If anywhere this should be moved to dotnet/runtime, but this looks like a FullAOT limitation to me. |
Description
It seems like signed release build ios applications have some problems serializing and deserializing generics using Newtonsoft.Json library. When you try to serialize or deserialize an object inherited by a baseclass which implements an interface of a generic type, you get an exception, that the properties, which are defined in the the interface could not be set or get during serialization or deserialization. According to the stack trace, the app crashes with the additional error "Attempting to JIT compile method '(wrapper delegate-invoke)' while running in aot-only mode. See https://docs.microsoft.com/xamarin/ios/internals/limitations for more information. (System.ExecutionEngineException)".
This error only occurs on release builds in signed ios applications on physical devices and with Newtonsoft.Json library. Using System.Text.Json the serialization and deserialization of objects behaves as expected.
I ran the iOS application on an M1 Macbook and received the crash log which I will attach in the section below
Sample demo:
Deserializable_Demo.zip
The issue in the attached demo is caused by implementing "IDeserializable where T : IDeserializable, new ()" Deserializable.cs
Steps to Reproduce
1.) Run the attached demo on ios-simulator and serialize/deserialize the DeserializableBase object by clicking the "Serialize/Deserialize me" Button in MainPage.xaml.cs. You can notice, that both serializers behaves as expected. Both labels "System.Text.Json" and "Newtonsoft.Json" indicates the status "Ok". The application does not crash.
2.) build the attached demo in release mode, sign it with your provisioning profile and run it on a physical device. Try to serialize/deserialize the DeserializableBase object by clicking the "Serialize/Deserialize me" Button. You can now notice, that the application crashes and produces the error described previously
Version with bug
6.0.400 (current)
Last version that worked well
Unknown/Other
Affected platforms
iOS, I was not able test on other platforms
Affected platform versions
iOS 15.4.1
Did you find any workaround?
I'm not aware of any workaround other than replacing Newtonsoft.Json library entirely with System.Json.Text.
Relevant log output
The text was updated successfully, but these errors were encountered: