Bug description
When running a xamarin forms app on an iOS device, while using pre-compilation, the MessagePackSerializer.Deserialize method throws an exception (System.NotImplementedException: byref delegate)
I've followed the readme https://github.com/neuecc/MessagePack-CSharp#aot-code-generation-support-for-unityxamarin and implemented the MS build task as described here https://github.com/neuecc/MessagePack-CSharp/blob/master/doc/msbuildtask.md to use pre-compiled types.
Repro steps
I've uploaded a small reproduction sample here: https://github.com/stefanbogaard86/MessagePack-iOS-sample,
this is the sample code:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using MessagePack;
using Xamarin.Forms;
using MessagePack.Resolvers;
namespace MessagePackSample
{
[MessagePackObject]
public class CustomObject
{
[Key(0)]
public string Item1 { get; set; }
[Key(1)]
public DateTime Item2 { get;set; }
public override string ToString()
{
return $"[{Item1} - {Item2.ToShortDateString()}]";
}
}
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
protected override void OnAppearing()
{
base.OnAppearing();
MessagePackSerializerOptions generatedResolverOptions =
MessagePackSerializerOptions.Standard
.WithResolver(
CompositeResolver.Create(
GeneratedResolver.Instance,
StandardResolver.Instance
));
var customObjects = new List<CustomObject>
{
new CustomObject() {Item1 = "Yesterday", Item2 = DateTime.Today.AddDays(-1)},
new CustomObject() {Item1 = "Today", Item2 = DateTime.Today},
new CustomObject() {Item1 = "Next week", Item2 = DateTime.Today.AddDays(7)}
};
var serializedObj = MessagePackSerializer.Serialize(customObjects, generatedResolverOptions);
try
{
var deserializedObj =
(IEnumerable<CustomObject>)MessagePackSerializer.Deserialize(typeof(IEnumerable<CustomObject>), serializedObj, generatedResolverOptions);
}
catch(Exception ex)
{
Debug.WriteLine(ex);
}
}
}
}
Expected behavior
The serialized object is deserialized when running a xamarin forms app on iOS.
Actual behavior
When trying to deserialize on xamarin forms iOS, an exception is thrown.
{System.NotImplementedException: byref delegate at System.Linq.Expressions.Interpreter.LightLambda.CreateCustomDelegate (System.Type delegateType) [0x001cf] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/LightLambda.cs:422 at System.Linq.Expressions.Interpreter.LightLambda.MakeDelegate (System.Type delegateType) [0x00012] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/LightLambda.cs:446 at System.Linq.Expressions.Interpreter.LightDelegateCreator.CreateDelegate (System.Runtime.CompilerServices.IStrongBox[] closure) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/LightDelegateCreator.cs:33 at System.Linq.Expressions.Interpreter.LightDelegateCreator.CreateDelegate () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/LightDelegateCreator.cs:28 at System.Linq.Expressions.Expression1[TDelegate].Compile (System.Boolean preferInterpretation) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/System.Linq.Expressions/src/System/Linq/Expressions/LambdaExpression.cs:211 at MessagePack.MessagePackSerializer+CompiledMethods..ctor (System.Type type) [0x0046d] in <e372d2478807460eabc86dc315aa3ac8>:0 at MessagePack.MessagePackSerializer+<>c.<.cctor>b__45_0 (System.Type t) [0x00000] in <e372d2478807460eabc86dc315aa3ac8>:0 at MessagePack.Internal.ThreadsafeTypeKeyHashTable1[TValue].AddToBuckets (MessagePack.Internal.ThreadsafeTypeKeyHashTable1+Entry[TValue][] buckets, System.Type newKey, MessagePack.Internal.ThreadsafeTypeKeyHashTable1+Entry[TValue] newEntryOrNull, System.Func2[T,TResult] valueFactory, TValue& resultingValue) [0x00045] in <e372d2478807460eabc86dc315aa3ac8>:0 at MessagePack.Internal.ThreadsafeTypeKeyHashTable1[TValue].TryAddInternal (System.Type key, System.Func2[T,TResult] valueFactory, TValue& resultingValue) [0x000d2] in <e372d2478807460eabc86dc315aa3ac8>:0 at MessagePack.Internal.ThreadsafeTypeKeyHashTable1[TValue].GetOrAdd (System.Type key, System.Func2[T,TResult] valueFactory) [0x0000d] in <e372d2478807460eabc86dc315aa3ac8>:0 at MessagePack.MessagePackSerializer.GetOrAdd (System.Type type) [0x00000] in <e372d2478807460eabc86dc315aa3ac8>:0 at MessagePack.MessagePackSerializer.Deserialize (System.Type type, System.ReadOnlyMemory1[T] bytes, MessagePack.MessagePackSerializerOptions options, System.Threading.CancellationToken cancellationToken) [0x00000] in :0 at MessagePackSample.MainPage.OnAppearing () [0x000f5] in C:\Projects\MessagePack-iOS-sample\MessagePackSample\MessagePackSample\MessagePackSample\MainPage.xaml.cs:54 }
- Version used:
Mono Framework MDK
Runtime:
Mono 6.12.0.140 (2020-02/51d876a041e) (64-bit)
Package version: 612000140
Xamarin.Forms 5.0.0.2125
MessagePack 2.3.85
MessagePack.MSBuild.Task 2.3.85
Additional context
It's working as expected on Android.
Bug description
When running a xamarin forms app on an iOS device, while using pre-compilation, the MessagePackSerializer.Deserialize method throws an exception (System.NotImplementedException: byref delegate)
I've followed the readme https://github.com/neuecc/MessagePack-CSharp#aot-code-generation-support-for-unityxamarin and implemented the MS build task as described here https://github.com/neuecc/MessagePack-CSharp/blob/master/doc/msbuildtask.md to use pre-compiled types.
Repro steps
I've uploaded a small reproduction sample here: https://github.com/stefanbogaard86/MessagePack-iOS-sample,
this is the sample code:
Expected behavior
The serialized object is deserialized when running a xamarin forms app on iOS.
Actual behavior
When trying to deserialize on xamarin forms iOS, an exception is thrown.
{System.NotImplementedException: byref delegate at System.Linq.Expressions.Interpreter.LightLambda.CreateCustomDelegate (System.Type delegateType) [0x001cf] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/LightLambda.cs:422 at System.Linq.Expressions.Interpreter.LightLambda.MakeDelegate (System.Type delegateType) [0x00012] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/LightLambda.cs:446 at System.Linq.Expressions.Interpreter.LightDelegateCreator.CreateDelegate (System.Runtime.CompilerServices.IStrongBox[] closure) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/LightDelegateCreator.cs:33 at System.Linq.Expressions.Interpreter.LightDelegateCreator.CreateDelegate () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/LightDelegateCreator.cs:28 at System.Linq.Expressions.Expression1[TDelegate].Compile (System.Boolean preferInterpretation) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/System.Linq.Expressions/src/System/Linq/Expressions/LambdaExpression.cs:211 at MessagePack.MessagePackSerializer+CompiledMethods..ctor (System.Type type) [0x0046d] in <e372d2478807460eabc86dc315aa3ac8>:0 at MessagePack.MessagePackSerializer+<>c.<.cctor>b__45_0 (System.Type t) [0x00000] in <e372d2478807460eabc86dc315aa3ac8>:0 at MessagePack.Internal.ThreadsafeTypeKeyHashTable1[TValue].AddToBuckets (MessagePack.Internal.ThreadsafeTypeKeyHashTable1+Entry[TValue][] buckets, System.Type newKey, MessagePack.Internal.ThreadsafeTypeKeyHashTable1+Entry[TValue] newEntryOrNull, System.Func2[T,TResult] valueFactory, TValue& resultingValue) [0x00045] in <e372d2478807460eabc86dc315aa3ac8>:0 at MessagePack.Internal.ThreadsafeTypeKeyHashTable1[TValue].TryAddInternal (System.Type key, System.Func2[T,TResult] valueFactory, TValue& resultingValue) [0x000d2] in <e372d2478807460eabc86dc315aa3ac8>:0 at MessagePack.Internal.ThreadsafeTypeKeyHashTable1[TValue].GetOrAdd (System.Type key, System.Func2[T,TResult] valueFactory) [0x0000d] in <e372d2478807460eabc86dc315aa3ac8>:0 at MessagePack.MessagePackSerializer.GetOrAdd (System.Type type) [0x00000] in <e372d2478807460eabc86dc315aa3ac8>:0 at MessagePack.MessagePackSerializer.Deserialize (System.Type type, System.ReadOnlyMemory1[T] bytes, MessagePack.MessagePackSerializerOptions options, System.Threading.CancellationToken cancellationToken) [0x00000] in :0 at MessagePackSample.MainPage.OnAppearing () [0x000f5] in C:\Projects\MessagePack-iOS-sample\MessagePackSample\MessagePackSample\MessagePackSample\MainPage.xaml.cs:54 }Mono Framework MDK
Runtime:
Mono 6.12.0.140 (2020-02/51d876a041e) (64-bit)
Package version: 612000140
Xamarin.Forms 5.0.0.2125
MessagePack 2.3.85
MessagePack.MSBuild.Task 2.3.85
Additional context
It's working as expected on Android.