I've been using DataContract serialization (using the System.Runtime.Serialization.DataContractSerializer) successfully for a while now to transfer data over a network in a UWP app (HoloLens), however when trying to port the project to IL2CPP I haven't been able to use this serializer anymore.
The exception it is throwing is:> System.NotSupportedException: IL2CPP does not support marshaling delegates that point to instance methods to native code. The method we're attempting to marshal is: System.Runtime.Diagnostics.DiagnosticsEventProvider::EtwEnableCallBack".
The mentioned EtwEnableCallback isn't something that is in any of my classes, so I'm guessing it is ingested by some of the Serialization attributes? Is there a way around this error?
Example code - Simple example class to be serialized: [Serializable] public class DataContractSerializationTest { [DataMember] public string TestValue = "test"; }
Example code - Serialization: DataContractSerializer serializerTest = new DataContractSerializer(typeof(DataContractSerializationTest)); MemoryStream streamTest = new MemoryStream(); using (var writerTest = XmlDictionaryWriter.CreateBinaryWriter(streamTest)) { serializerTest.WriteObject(writerTest, new DataContractSerializationTest()); // It throws the exception here }
The exception it is throwing is:> System.NotSupportedException: IL2CPP does not support marshaling delegates that point to instance methods to native code. The method we're attempting to marshal is: System.Runtime.Diagnostics.DiagnosticsEventProvider::EtwEnableCallBack".
The mentioned EtwEnableCallback isn't something that is in any of my classes, so I'm guessing it is ingested by some of the Serialization attributes? Is there a way around this error?
Example code - Simple example class to be serialized: [Serializable] public class DataContractSerializationTest { [DataMember] public string TestValue = "test"; }
Example code - Serialization: DataContractSerializer serializerTest = new DataContractSerializer(typeof(DataContractSerializationTest)); MemoryStream streamTest = new MemoryStream(); using (var writerTest = XmlDictionaryWriter.CreateBinaryWriter(streamTest)) { serializerTest.WriteObject(writerTest, new DataContractSerializationTest()); // It throws the exception here }