From c3affed9b17c6af2ec9a1e9a4958682d8a9ff6ba Mon Sep 17 00:00:00 2001 From: Flamefire Date: Fri, 24 Oct 2014 23:08:15 +0200 Subject: [PATCH] Fix handling of nullables Improve error handling --- VocaluxeLib/Xml/CMyXmlDeserializer.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/VocaluxeLib/Xml/CMyXmlDeserializer.cs b/VocaluxeLib/Xml/CMyXmlDeserializer.cs index 10ef6a53..f46c69c7 100644 --- a/VocaluxeLib/Xml/CMyXmlDeserializer.cs +++ b/VocaluxeLib/Xml/CMyXmlDeserializer.cs @@ -173,7 +173,7 @@ namespace VocaluxeLib.Xml if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>)) { Type subType = type.GetGenericArguments()[0]; - return _GetPrimitiveValue(node, subType); + return _GetValue(node, subType); } object value = Activator.CreateInstance(type); @@ -189,9 +189,13 @@ namespace VocaluxeLib.Xml { value = Convert.ChangeType(node.InnerText, type, CultureInfo.InvariantCulture); } - catch (FormatException) + catch (FormatException e) { - throw new XmlException("Invalid format in " + _FindXPath(node) + ": '" + node.InnerText + "'"); + throw new XmlException("Invalid format in " + _FindXPath(node) + ": '" + node.InnerText + "' (" + e.Message + ")"); + } + catch (InvalidCastException e) + { + throw new XmlException(e.Message + " in " + _FindXPath(node) + ": '" + node.InnerText + "'"); } return value; }