This is a migrated thread and some comments may be shown as answers.

Error persisting: "There was an error generating the XML document"

3 Answers 1596 Views
PersistenceFramework
This is a migrated thread and some comments may be shown as answers.
Igor
Top achievements
Rank 1
Igor asked on 13 May 2013, 11:18 AM
Hi, 

we have Silverlight 4 project with RadTileView component and on it a couple of tiles,with RadGridView controls etc...

Depending on the layout of our page we get the error when trying to save layout.
It happens only in certain scenarios,and we couldn't find the reason why it might be.

The error is:
System.InvalidOperationException
"There was an error generating the XML document."

Stack trace:

at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle)
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces)
at System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter, Object o, XmlSerializerNamespaces namespaces)
at System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter, Object o)
at Telerik.Windows.Persistence.Serialization.Serializer.Serialize(Object obj)
at Telerik.Windows.Persistence.PersistenceManager.Save(Object obj)
at InsaSLPortalApp.ContentPage.PersistLayout()
at InsaSLPortalApp.ContentPage.ContentPage_Unloaded(Object sender, RoutedEventArgs e)
at MS.Internal.CoreInvokeHandler.InvokeEventHandler(UInt32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName, UInt32 flags)


InnerException:
The type System.Collections.Generic.KeyValuePair`2[[System.String, mscorlib, Version=5.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.String, mscorlib, Version=5.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]] was not expected. Use the XmlInclude attribute to specify types that are not known statically.

The version of the PersistanceFramework is: 2011.2.712.1040

Thank you,
Igor

3 Answers, 1 is accepted

Sort by
0
Zarko
Telerik team
answered on 16 May 2013, 08:07 AM
Hello Igor,
From your stack trace and the innerException I can see that you're trying to serialize a KeyValuePair<string, string> and I guess this comes from a dictionary<string, string> but the XML serializer can't save IDictionary objects:
Q: Why can't I serialize hashtables?
A: The XmlSerializer cannot process classes implementing the IDictionary interface. This was partly due to schedule constraints and partly due to the fact that a hashtable does not have a counterpart in the XSD type system. The only solution is to implement a custom hashtable that does not implement the IDictionary interface.
Instead of saving dictionary<string, string> you could try to convert it to List<MyObject> where MyObject is:
public class MyObject
{
    public MyObject()
    { }
 
    public string Key { get; set; }
    public string Value { get; set; }
}
(note: the default constructor is important so that the Activator could create an instance of this class)
I hope I was able to help you and if you have further questions please feel free to ask.

All the best,
Zarko
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
IgyBoy
Top achievements
Rank 1
answered on 16 May 2013, 08:24 AM

Hello Zarko,
thank you for you reply.

Actually, I'm not serializing KeyValuePair objects. I'm trying to serialize RadTileView component(it's layout).

   

    
PersistenceManager manager = new PersistenceManager();
try
{
   Stream TilesStream = manager.Save(radTileView1); // <- here it breaks, "radTileview1" is the RadTileView component we try to serialize
    //save the stream to isolated storage
    SaveLayoutToIsolatedStorage("Tiles.ins", TilesStream);
}
catch (Exception ex)
{
   //ErrorWindow.CreateNew(ex);
}

I could paste the code,but I'm not sure it would help,since it doesn't always happen.
 
Regards,
Igor
0
Zarko
Telerik team
answered on 20 May 2013, 03:03 PM
Hi Igor,
Unfortunately I'm not able to reproduce this issue so I'd like to ask you for some code snippets or a sample project (this would be best) so that we could examine your case and try to find the cause of this problem.
We're looking forward to hearing from you.

Kind regards,
Zarko
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
PersistenceFramework
Asked by
Igor
Top achievements
Rank 1
Answers by
Zarko
Telerik team
IgyBoy
Top achievements
Rank 1
Share this question
or