Quantcast
Viewing all articles
Browse latest Browse all 2383

UsedOnlyForAOTCodeGeneration - not managed to make it work

Hello I am trying to use JSON serialization, but I am always getting ExecutionEngineException: Attempting to call method 'System.Runtime.Serialization.XmlObjectSerializerReadContext::EnsureArraySize' for which no ahead of time (AOT) code was generated. I wrote the below function in the class where I am trying ReadObject that crashes. public static void UsedOnlyForAOTCodeGeneration() { DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(ProfileConfig)); ; byte[] data; FilesManager.ReadFile("test.txt", out data); string jsonString = Encoding.UTF8.GetString(data); ; Stream ms = new MemoryStream(Encoding.UTF8.GetBytes(jsonString)); ProfileConfig profile = null; profile = (ProfileConfig)serializer.ReadObject(ms); // Include an exception so we can be sure to know if this method is ever called. throw new System.InvalidOperationException("This method is used for AOT code generation only. Do not call it at runtime."); } ProfileConfig is a structure, that contains and array: my_structure[] complete_structure; I tried to allocate the ProfileConfig and all its components , no luck. What can I do more? Thank you for any hint.

Viewing all articles
Browse latest Browse all 2383

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>