Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Problem to Deserialize Guid?

$
0
0

Hi everyone,
I have a problem with a json net Deserialize.
In my string, i have a property Guid? set to null, the deserializer throw a exception.

Code

`var result = DependencyService.Get().LoadText(FileName);
Newtonsoft.Json.JsonSerializer js = new Newtonsoft.Json.JsonSerializer();
try
{
using (var sr = new StringReader(result))
using (var jr = new JsonTextReader(sr))
{
Data = js.Deserialize(jr);

            } 
        }
        catch (JsonSerializationException e)
        {
            Debug.WriteLine(e.Message);
        }`

Json

\"Answers\": [
                        {
                            \"Id\": \"c1a972b4-387d-4518-9578-808befac6d3a\",
                            \"Name\": \"xx\",
                            \"Phone\": \"00\",
                            \"Mail\": null,
                            \"Index\": 1,
                            \"PossibleAnswerId\": null,
                            \"PossibleAnswers\": null,
                        },
                        {
                            \"Id\": \"92f54187-c5fa-425f-83c1-5c96369d5909\",
                            \"Name\": \"xx\",
                            \"Phone\": \"000\",
                            \"Mail\": null,
                            \"Index\": 2,
                            \"PossibleAnswerId\": null,
                            \"PossibleAnswers\": null,
                        }
                    ]

Exception

{Newtonsoft.Json.JsonSerializationException: Error setting value to 'PossibleAnswerId' on 'Answer'. ---> 
System.TypeInitializationException: An exception was thrown by the type initializer for Microsoft.Scripting.Interpreter.InstructionFactory
1 --->
System.ExecutionEngineException: Attempting to JIT compile method 'Microsoft.Scripting.Interpreter.InstructionFactory`1<System.Guid>:.cctor ()'
while running with --aot-only. See http://docs.xamarin.com/ios/about/limitations for more information.

--- End of inner exception stack trace ---
at (wrapper managed-to-native) System.Reflection.MonoField:GetValueInternal (System.Reflection.MonoField,object)
at System.Reflection.MonoField.GetValue (System.Object obj) [0x0006a] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Reflection/MonoField.cs:125
at Microsoft.Scripting.Interpreter.InstructionFactory.GetFactory (System.Type type) [0x0015e] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.4.0.16/src/mono/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/InstructionFactory.cs:60
at Microsoft.Scripting.Interpreter.InstructionList.EmitDefaultValue (System.Type type) [0x00000] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.4.0.16/src/mono/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/InstructionList.cs:775
at Microsoft.Scripting.Interpreter.LightCompiler.CompileNewExpression (System.Linq.Expressions.Expression expr) [0x000b6] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.4.0.16/src/mono/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/LightCompiler.cs:1362
at Microsoft.Scripting.Interpreter.LightCompiler.CompileNoLabelPush (System.Linq.Expressions.Expression expr) [0x002fb] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.4.0.16/src/mono/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/LightCompiler.cs:1667
at Microsoft.Scripting.Interpreter.LightCompiler.Compile (System.Linq.Expressions.Expression expr) [0x00008] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.4.0.16/src/mono/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/LightCompiler.cs:1729
at Microsoft.Scripting.Interpreter.LightCompiler.CompileConvertUnaryExpression (System.Linq.Expressions.Expression expr) [0x00086] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.4.0.16/src/mono/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/LightCompiler.cs:684
at Microsoft.Scripting.Interpreter.LightCompiler.CompileNoLabelPush (System.Linq.Expressions.Expression expr) [0x001ff] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.4.0.16/src/mono/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/LightCompiler.cs:1646
at Microsoft.Scripting.Interpreter.LightCompiler.Compile (System.Linq.Expressions.Expression expr) [0x00008] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.4.0.16/src/mono/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/LightCompiler.cs:1729
at Microsoft.Scripting.Interpreter.LightCompiler.CompileTop (System.Linq.Expressions.LambdaExpression node) [0x00055] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.4.0.16/src/mono/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/LightCompiler.cs:221
at Microsoft.Scripting.Generation.CompilerHelpers.LightCompile (System.Linq.Expressions.LambdaExpression lambda) [0x00000] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.4.0.16/src/mono/mcs/class/dlr/Runtime/Microsoft.Dynamic/Generation/CompilerHelpers.cs:619
at System.Linq.Expressions.Compiler.LambdaCompiler.Compile (System.Linq.Expressions.LambdaExpression lambda, System.Runtime.CompilerServices.DebugInfoGenerator debugInfoGenerator) [0x00000] in :0
at System.Linq.Expressions.LambdaExpression.Compile () [0x00000] in :0
at Newtonsoft.Json.Utilities.ExpressionReflectionDelegateFactory.CreateDefaultConstructor[Object] (System.Type type) [0x00000] in :0
--- End of inner exception stack trace ---
at Newtonsoft.Json.Serialization.ExpressionValueProvider.SetValue (System.Object target, System.Object value) [0x00000] in :0
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue (Newtonsoft.Json.Serialization.JsonProperty property, Newtonsoft.Json.JsonConverter propertyConverter, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerProperty, Newtonsoft.Json.JsonReader reader, System.Object target) [0x00000] in :0
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject (System.Object newObject, Newtonsoft.Json.JsonReader reader, Newtonsoft.Json.Serialization.JsonObjectContract contract, Newtonsoft.Json.Serialization.JsonProperty member, System.String id) [0x00000] in :0 }`

Thanks for your help.


Viewing all articles
Browse latest Browse all 58056

Trending Articles