Closed nvdovkin closed 1 year ago
~Reading through the logs I see~
~Error getting value from 'Id' on 'Models.Deserializable.DeserializableBase'~
~Isn't that the actual error? Something not being able to deserialize? Does this code work in a non-MAUI app?~
Ah I see, it does work in debug. Seems that maybe Newtonsoft.Json isn't linker safe?
Hi @nvdovkin. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. 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.
~Reading through the logs I see~
~Error getting value from 'Id' on 'Models.Deserializable.DeserializableBase'~
~Isn't that the actual error? Something not being able to deserialize? Does this code work in a non-MAUI app?~
Ah I see, it does work in debug. Seems that maybe Newtonsoft.Json isn't linker safe?
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.
at <unknown> <0xffffffff>
at <unknown> <0xffffffff>
at System.Delegate:CreateDelegate_internal <0x0002e>
at System.Delegate:CreateDelegate <0x00194>
at System.Delegate:CreateDelegate <0x00026>
at System.Delegate:CreateDelegate <0x00020>
at System.Reflection.Emit.DynamicMethod:CreateDelegate <0x0008a>
at System.Text.Json.Serialization.Metadata.ReflectionEmitMemberAccessor:CreateDelegate <0x00036>
at System.Text.Json.Serialization.Metadata.ReflectionEmitMemberAccessor:CreatePropertyGetter <0x0001e>
at System.Text.Json.Serialization.Metadata.JsonPropertyInfo`1:Initialize <0x0016e>
at System.Text.Json.Serialization.Metadata.JsonTypeInfo:CreateProperty <0x0008c>
at System.Text.Json.Serialization.Metadata.JsonTypeInfo:AddProperty <0x00156>
at System.Text.Json.Serialization.Metadata.JsonTypeInfo:CacheMember <0x000a8>
at System.Text.Json.Serialization.Metadata.JsonTypeInfo:.ctor <0x003b0>
at System.Text.Json.Serialization.Metadata.JsonTypeInfo:.ctor <0x0004a>
at System.Text.Json.JsonSerializerOptions:<InitializeForReflectionSerializer>g__CreateJsonTypeInfo|112_0 <0x00018>
at System.Text.Json.JsonSerializerOptions:GetClassFromContextOrCreate <0x000c4>
at System.Text.Json.JsonSerializerOptions:GetOrAddClass <0x00066>
at System.Text.Json.Serialization.Metadata.JsonTypeInfo:get_ElementTypeInfo <0x0006a>
at System.Text.Json.Serialization.JsonCollectionConverter`2:OnTryRead <0x0002a>
at System.Text.Json.Serialization.JsonConverter`1:TryRead <0x0049a>
at System.Text.Json.Serialization.JsonConverter`1:ReadCore <0x0025c>
at System.Text.Json.JsonSerializer:ReadCore <0x00052>
at System.Text.Json.JsonSerializer:ReadCore <0x0008c>
at System.Text.Json.JsonSerializer:ContinueDeserialize <0x0018e>
at <ReadAllAsync>d__65`1:MoveNext <0x00328>
at System.Runtime.CompilerServices.AsyncMethodBuilderCore:Start <0x0008c>
at System.Runtime.CompilerServices.AsyncValueTaskMethodBuilder`1:Start <0x00010>
at System.Text.Json.JsonSerializer:ReadAllAsync <0x00098>
at System.Text.Json.JsonSerializer:DeserializeAsync <0x00064>
at System.Net.Http.Json.HttpContentJsonExtensions:DeserializeAsyncHelper <0x0001e>
at <ReadFromJsonAsyncCore>d__4`1:MoveNext <0x0021e>
at System.Runtime.CompilerServices.AsyncMethodBuilderCore:Start <0x0008c>
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:Start <0x00010>
at System.Net.Http.Json.HttpContentJsonExtensions:ReadFromJsonAsyncCore <0x000ae>
at System.Net.Http.Json.HttpContentJsonExtensions:ReadFromJsonAsync <0x000b0>
at <GetAsync>d__0:MoveNext <0x00256>
at AsyncStateMachineBox`1:ExecutionContextCallback <0x00024>
at System.Threading.ExecutionContext:RunInternal <0x0011e>
at AsyncStateMachineBox`1:MoveNext <0x000d0>
at AsyncStateMachineBox`1:MoveNext <0x00014>
at <>c:<.cctor>b__17_0 <0x00020>
at System.Threading.Tasks.AwaitTaskContinuation:RunCallback <0x00084>
at System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation:Run <0x00062>
at System.Threading.Tasks.Task:RunContinuations <0x001c4>
at System.Threading.Tasks.Task:FinishContinuations <0x00050>
at System.Threading.Tasks.Task`1:TrySetResult <0x000de>
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:SetExistingTaskResult <0x0006a>
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:SetResult <0x00056>
at <TryGet>d__2:MoveNext <0x0142e>
at AsyncStateMachineBox`1:ExecutionContextCallback <0x00024>
at System.Threading.ExecutionContext:RunInternal <0x0011e>
at AsyncStateMachineBox`1:MoveNext <0x000d0>
at AsyncStateMachineBox`1:MoveNext <0x00014>
at <>c:<.cctor>b__8_0 <0x00020>
at Foundation.NSAsyncSynchronizationContextDispatcher:Apply <0x0002e>
at System.Object:runtime_invoke_direct_void__this__ <0x00080>
at <unknown> <0x00000>
at <unknown> <0xffffffff>
at UIKit.UIApplication:UIApplicationMain <0x001c6>
at UIKit.UIApplication:Main <0x0011c>
at CompanyPortal.Components.Program:Main <0x00030>
at <Module>:runtime_invoke_direct_void_string[] <0x00076>
at <unknown> <0x00000>
We're experiencing a similar issues with Json (Newtonsoft) encoding as well. (Attempting to get information from a website, and then retrieve it.)
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.
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 | ✅ | iOS Simulator Release | ✅ | iOS Device Debug | ✅ | iOS Device Release | ❌ | iOS Signed Release
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?
@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