I have a project that I need to upgrade to .net 4 and now my serialized xaml that contained generic types is broken when I call xamlreader.
Because of the upgrade I am now using System.Xaml.XamlServices instead of System.Windows.Markup to read the xaml.
//o=System.Windows.Markup.XamlReader.Parse((String)value);
o = System.Xaml.XamlServices.Parse(value as string);
//o = System.Xaml.XamlServices.Load((String)value);
Here's a sample of the xaml I've tried to read. I've experiemented with changing the name spaces from '2006' to '2009'...
<my:UserColors
xmlns="http://schemas.microsoft.com/winfx/2009/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:my="clr-namespace:MyApp;assembly=MyApp"
x:TypeArguments="my:UserColor"
>
<my:UserColor ColorName="RedCustom" Color="#FFFF0017"/>
<my:UserColor ColorName="GreenCustom" Color="#FF26C671"/>
</my:UserColors>
According to some articles (I have pasted the relevant URLs below), Xaml 2009, which allows for generic types, is only useable in 'loose xaml' but not 'compiled xaml' (ie: xaml that we want to serialize/deserialize).
Because of that, this Xaml Object Exception occurs:
"Cannot set unknown member '{http://schemas.microsoft.com/winfx/2009/xaml}TypeArguments'.' Line number '5' and line position '1'"
I am understanding this is down to me adding this line:
x:TypeArguments="my:UserColor"
Note that in my example, I've defined UserColors (with an s) as an ObservableCollection of UserColor.
I've tried different variations of getting this to work... Using the 2006 xaml, trying to treat the serialized data as string (e.g.
x:TypeArguments="x:String"
(here are some related links)
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/e288979e-1adf-47a2-af72-e61e9ff90bc6
http://msdn.microsoft.com/en-us/library/ee956431.aspx
http://social.msdn.microsoft.com/forums/en-US/wpf/thread/2b5f8ab5-e3ad-4f5f-b1fc-177b29f369d2/
http://www.wpftutorial.net/XAML2009.html#generics