Closed ricavir11 closed 4 years ago
It looks like we're running into a AOT issue:
{System.ExecutionEngineException: Attempting to JIT compile method '(wrapper delegate-invoke) System.Nullable1<int> <Module>:invoke_callvirt_Nullable1_SendChatMessageInput (Services.Chat.SendChatMessageInput)' while running in aot-only mode. See https://docs.microsoft.com/xamarin/ios/internals/limitations for more information.
Could you please attach a sample project, as we'll likely need it to run down this bug.
Yes seems to be AOT issue. Can't share the project in public, I will send you a link by mail.
Is the Logisav
e-mail I have that link?
You have received another email to donwload the project, the first one was for your credentials
I have been able to reproduce and it is internal bug 1020091
@chamons what is the root cause ? problem with a specific object/interface or simply broken for all use cases?
This has been tracked down to an issue in work at https://github.com/mono/mono/pull/17832
From the internal bug:
It looks like System.Text.Json was not designed to work in full-aot environments, esp the class ReflectionMemberAccessor.
A possible workaround is to avoid using nullable fields in the classes which are serialized/deserialized to/from JSON.
@chamons Thank you vm!
If this is pure AOT issue then using MessagePack instead of Json serializer would not raise same issues ? - kindly confirm.
Unsure, I don't know how either of those libraries work under the hood.
@chamons thank you
MessagePack has tooling to pre-compile serialization/deserialization code and should be compatible with most use cases.
Maybe @ricavir11 could test it, switching from json would be trivial. Here are the docs:
MessagePack hub protocol description - msft.
The referenced package is Microsoft.AspNetCore.SignalR.Protocols.MessagePack which is some fork of MessagePack-CSharp - github
MessagePack AOT support doc is here
hi @rhy-ama ,
Unfortunately, I can't change server side easily... and from my understanding, MessagePack should b configured on server side.
Actualy, the application I'm working on is already in production with an angular web client (signal R OK), a Xamarin Android app (signal R OK) and a Xamarin iOS app which is causing the issue.
I can't ask to change all these apps just because of a serialization issue due to AOT on iOS.
Do you think we have a chance to have it fixed soon ? If so, do you have any time frame to provide ?
@ricavir11 @rhy-ama
The fix is in mono master, and will likely make a future release early this spring. It unfortunately is too late to get into the next major release.
It might be possible to get you folks a one-off build with the fix, but if you want an "official" build, we would need to make a service release.
To bring that up for consideration, you'd need to file an escalation. The link to create one depends on if you have any support contact from Microsoft (or Xamarin).:
Paid (Unified or Professional) Support - https://support.microsoft.com/en-us/help/4341255/support-for-business
Xamarin premier support - https://support.microsoft.com/en-us/premier
Wow, that's a huge one ! I've tried to open a support ticket but it seems also to have an issue :/
Unfortunately, I don't have a paid support available (or maybe with our azure subscription that is running ??).
Nevertheless, if we achieve to have a build earlier with this fix included, how can we add it to our projet ?
Are you building from VS Windows or VS for Mac? One is easier for you to get a one-off build and one will almost certainly require a service release for you to get the fix.
VS Windows
Ok - We're looking into when we'd be able to get this fix out.
There are a few more moving parts here than I expected in getting your a VS (Windows) build.
Found a workaround for this issue:
It looks like iOS is having problems with Guid/DateTime objects. The workaround is to pass an new object with only strings/int values:
await _connection.InvokeAsync("SendMessage", new { Id = message.Id.ToString(), Text = message.Text, DateCreated = message.DateCreated.ToString("yyyy-MM-ddTHH\\:mm\\:ss.fffffffzzz") });
Steps to Reproduce
{System.ExecutionEngineException: Attempting to JIT compile method '(wrapper delegate-invoke) System.Nullable_SendChatMessageInput (Services.Chat.SendChatMessageInput)' while running in aot-only mode. See https://docs.microsoft.com/xamarin/ios/internals/limitations for more information.
1<int> <Module>:invoke_callvirt_Nullable
1at System.Text.Json.ReflectionMemberAccessor+<>c__DisplayClass11_0:0
at Microsoft.AspNetCore.SignalR.Client.HubConnection.InvokeCore (Microsoft.AspNetCore.SignalR.Client.HubConnection+ConnectionState connectionState, System.String methodName, Microsoft.AspNetCore.SignalR.Client.Internal.InvocationRequest irq, System.Object[] args, System.String[] streams, System.Threading.CancellationToken cancellationToken) [0x00133] in :0
at Microsoft.AspNetCore.SignalR.Client.HubConnection.InvokeCoreAsyncCore (System.String methodName, System.Type returnType, System.Object[] args, System.Threading.CancellationToken cancellationToken) [0x00212] in :0
at System.Threading.Tasks.ForceAsyncAwaiter`1[T].GetResult () [0x0000c] in :0
at Microsoft.AspNetCore.SignalR.Client.HubConnection.InvokeCoreAsync (System.String methodName, System.Type returnType, System.Object[] args, System.Threading.CancellationToken cancellationToken) [0x0009e] in :0
at Services.Chat.ChatManager.SendMessageAsync (Services.Chat.SendChatMessageInput input) [0x00062] in C:\src\Mobile.Shared\Services\Chat\ChatManager.cs:88 }
2[TClass,TProperty].<CreatePropertyGetter>b__0 (System.Object obj) [0x00000] in <996dc3e1eb544ee0861c0639083a927e>:0 at System.Text.Json.JsonPropertyInfoNullable
2[TClass,TProperty].OnWrite (System.Text.Json.WriteStackFrame& current, System.Text.Json.Utf8JsonWriter writer) [0x0001c] in <996dc3e1eb544ee0861c0639083a927e>:0 at System.Text.Json.JsonPropertyInfo.Write (System.Text.Json.WriteStack& state, System.Text.Json.Utf8JsonWriter writer) [0x00029] in <996dc3e1eb544ee0861c0639083a927e>:0 at System.Text.Json.JsonSerializer.HandleObject (System.Text.Json.JsonPropertyInfo jsonPropertyInfo, System.Text.Json.JsonSerializerOptions options, System.Text.Json.Utf8JsonWriter writer, System.Text.Json.WriteStack& state) [0x0005f] in <996dc3e1eb544ee0861c0639083a927e>:0 at System.Text.Json.JsonSerializer.WriteObject (System.Text.Json.JsonSerializerOptions options, System.Text.Json.Utf8JsonWriter writer, System.Text.Json.WriteStack& state) [0x000d4] in <996dc3e1eb544ee0861c0639083a927e>:0 at System.Text.Json.JsonSerializer.Write (System.Text.Json.Utf8JsonWriter writer, System.Int32 originalWriterDepth, System.Int32 flushThreshold, System.Text.Json.JsonSerializerOptions options, System.Text.Json.WriteStack& state) [0x0005b] in <996dc3e1eb544ee0861c0639083a927e>:0 at System.Text.Json.JsonSerializer.WriteCore (System.Text.Json.Utf8JsonWriter writer, System.Text.Json.PooledByteBufferWriter output, System.Object value, System.Type type, System.Text.Json.JsonSerializerOptions options) [0x00050] in <996dc3e1eb544ee0861c0639083a927e>:0 at System.Text.Json.JsonSerializer.WriteValueCore (System.Text.Json.Utf8JsonWriter writer, System.Object value, System.Type type, System.Text.Json.JsonSerializerOptions options) [0x00016] in <996dc3e1eb544ee0861c0639083a927e>:0 at System.Text.Json.JsonSerializer.Serialize (System.Text.Json.Utf8JsonWriter writer, System.Object value, System.Type inputType, System.Text.Json.JsonSerializerOptions options) [0x00007] in <996dc3e1eb544ee0861c0639083a927e>:0 at Microsoft.AspNetCore.SignalR.Protocol.JsonHubProtocol.WriteArguments (System.Object[] arguments, System.Text.Json.Utf8JsonWriter writer) [0x00062] in <1496dd884aa74204bf430db4f9b7c287>:0 at Microsoft.AspNetCore.SignalR.Protocol.JsonHubProtocol.WriteInvocationMessage (Microsoft.AspNetCore.SignalR.Protocol.InvocationMessage message, System.Text.Json.Utf8JsonWriter writer) [0x0001f] in <1496dd884aa74204bf430db4f9b7c287>:0 at Microsoft.AspNetCore.SignalR.Protocol.JsonHubProtocol.WriteMessageCore (Microsoft.AspNetCore.SignalR.Protocol.HubMessage message, System.Buffers.IBufferWriter1[T] stream) [0x00080] in <1496dd884aa74204bf430db4f9b7c287>:0 at Microsoft.AspNetCore.SignalR.Protocol.JsonHubProtocol.WriteMessage (Microsoft.AspNetCore.SignalR.Protocol.HubMessage message, System.Buffers.IBufferWriter
1[T] output) [0x00000] in <1496dd884aa74204bf430db4f9b7c287>:0 at Microsoft.AspNetCore.SignalR.Client.HubConnection.SendHubMessage (Microsoft.AspNetCore.SignalR.Client.HubConnection+ConnectionState connectionState, Microsoft.AspNetCore.SignalR.Protocol.HubMessage hubMessage, System.Threading.CancellationToken cancellationToken) [0x00035] inExpected Behavior
A message is sent to the server
Actual Behavior
When running on real device (Debug or Release mode), message is not sent and an exception is thrown When running over iOS simulator, message is sent, no problem. Same code running on Android works as excepted.
Environment
Server : ASP.NET CORE 2.1
Client : Xamarin Forms v4.2 ; SignalR.Client v3.0.0