From 290f6e425f3b40c37d8149df04ac49ebd1534f34 Mon Sep 17 00:00:00 2001 From: maarten Date: Tue, 5 Apr 2016 09:48:33 +0200 Subject: [PATCH] Made sure deserialize throws a better exception when one of the members could not be deserialized --- .../StringableTypeSerializer.cs | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/Platform.Xml.Serialization/StringableTypeSerializer.cs b/src/Platform.Xml.Serialization/StringableTypeSerializer.cs index 06052dc..074d6d9 100644 --- a/src/Platform.Xml.Serialization/StringableTypeSerializer.cs +++ b/src/Platform.Xml.Serialization/StringableTypeSerializer.cs @@ -72,12 +72,25 @@ public override string Serialize(object obj, SerializationContext state) /// public override object Deserialize(string value, SerializationContext state) { - if (formatSpecified) - { - return Convert.ChangeType(value, supportedType, formatAttribute.CultureInfo); - } + + try + { + if (formatSpecified) + { + return Convert.ChangeType(value, supportedType, formatAttribute.CultureInfo); + } - return Convert.ChangeType(value, supportedType); + return Convert.ChangeType(value, supportedType); + } + catch(Exception ex) + { + var memberInfo = state.GetCurrentMemberInfo().MemberInfo; + throw new Exception(string.Format("Can't deserialize property {0} of class {1}. Could not convert value '{2}' to type {3}", + memberInfo.Name, + memberInfo.DeclaringType.FullName, + value, + supportedType), ex); + } } } }