XamlReader.Parse throws exception on empty String

Posted by sub-jp on Stack Overflow See other posts from Stack Overflow or by sub-jp
Published on 2010-03-23T18:45:21Z Indexed on 2010/05/11 8:54 UTC
Read the original article Hit count: 314

Filed under:
|
|
|

In our app, we need to save properties of objects to the same database table regardless of the type of object, in the form of propertyName, propertyValue, propertyType. We decided to use XamlWriter to save all of the given object's properties. We then use XamlReader to load up the XAML that was created, and turn it back into the value for the property. This works fine for the most part, except for empty strings. The XamlWriter will save an empty string as below.

<String xmlns="clr-namespace:System;assembly=mscorlib" xml:space="preserve" /> 

The XamlReader sees this string and tries to create a string, but can't find an empty constructor in the String object to use, so it throws a ParserException.

The only workaround that I can think of is to not actually save the property if it is an empty string. Then, as I load up the properties, I can check for which ones did not exist, which means they would have been empty strings.

Is there some workaround for this, or is there even a better way of doing this?

© Stack Overflow or respective owner

Related posts about c#

Related posts about xamlreader