XAML Serialization bug
-
Friday, March 19, 2010 5:10 PM
Hi all,
I have this class
public class XamlBugClass { List<string> myList = new List<string>(); public List<string> MyList { get { return myList; } set { myList = value; } } }this XAML
<XamlBugClass xmlns="clr-namespace:WindowsFormsApplication1;assembly=WindowsFormsApplication1" > <XamlBugClass.MyList> <String xmlns="clr-namespace:System;assembly=mscorlib" >hello world</String> <String xmlns="clr-namespace:System;assembly=mscorlib" >hello world2</String> </XamlBugClass.MyList> </XamlBugClass>and I do this operation
object t = XamlReader.Load(File.OpenRead("MySample.xaml")); string XAML = XamlWriter.Save(t);The Load just works perfect but when I get to the Save I get
"Cannot serialize a generic type 'System.Collections.Generic.List`1[System.String]'."
This does not make sense at all, so I consider it a bug.
Cheers,
Tobias
All Replies
-
Friday, March 19, 2010 5:57 PM
Hi Tobias,
WPF 3.X didn't really support generics correctly so that's why you're seeing this error. We're in the process of adding better generics support to XAML (loose XAML in System.Xaml supports it but the BAML compiler doesnt').
If you're just serializing data types and not WPF objects, you can use XamlServices.Load/Save in System.Xaml.dll in .NET 4 to serialize this. I just tried serializing your XAML and I got:
<XamlBugClass xmlns="clr-namespace:ConsoleApplication25;assembly=ConsoleApplication25" xmlns:scg="clr-namespace:System.Collections.Generic;assembly=mscorlib" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <XamlBugClass.MyList> <scg:List x:TypeArguments="x:String" Capacity="4"> <x:String>hello world</x:String> <x:String>hello world2</x:String> </scg:List> </XamlBugClass.MyList> </XamlBugClass>- Mike- Marked As Answer by Tobias Manthey Friday, March 19, 2010 6:18 PM
-
Monday, August 30, 2010 12:28 AM
Hi all,
I have this class
this XAML
and I do this operation
The Load just works perfect but when I get to the Save I get
"Cannot serialize a generic type 'System.Collections.Generic.List`1[System.String]'."
This does not make sense at all, so I consider it a bug.
Cheers,
Tobias
If you're sure it's a bug, You may tell the developing team. -
Monday, August 30, 2010 4:35 AMIt has already been fixed in .Net 4 .
-
Thursday, October 14, 2010 12:47 PM
No, it hasn't.
In case you are familiar with using the "DelegateCommand" class for encapsulating command logic in MVVM - otherwise google on the web for implementation, I have just tried serializing an XAML which had bound commands like DelegateCommand<string> to its command properties. XamlWriter would throw that very same exception.
Still looking for a workaround ever since.
C.
-
Monday, May 16, 2011 2:15 AMIs there any solutions about this problem?

