Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Saturday, September 10, 2011 2:36 PM
My project is WPF and bases on Kinect SkeletalViewer Sample. I add a function to save Joint Collection, but the error message(as below) appear when I save the KinectJointCollection. Does somebody know how to solve this problem?
There was an error reflecting type 'FileAccessor.KinectJointCollection'.
namespace FileAccessor
{
public class KinectJointCollection
{
public KinectJointCollection()
{
Joints = new List<JointsCollection>();
}
public List<JointsCollection> Joints;
}
public static class XMLAccessor
{
public static bool SaveKinectKeyFrameToXML(string filename, KinectJointCollection kJointCollection)
{
FileStream stream = File.Open(filename, FileMode.Create);
XmlSerializer serializer = new XmlSerializer(typeof(KinectJointCollection));
serializer.Serialize(stream, kJointCollection);
stream.Close();
return true;
}
akira32 編程之家 Yahoo http://tw.myblog.yahoo.com/akira32-akira32
All replies (10)
Monday, September 12, 2011 12:32 PM ✅Answered
Yes the XMLSerializer will only serialize the public members. If you have private member variables they will not get serialized, except indirectly if there is an exposed property that has a get on the private variable. Likewise, if you have a read only property it won't get serialized.Tom Overton
Saturday, September 10, 2011 4:13 PM
Maybe JointsCollection is an object that is not serializable? Tom Overton
Saturday, September 10, 2011 4:14 PM
Hi
What is the InnerException?...Generally in this case it gives clear description what property XMLSerializer find difficulty to deal with...
If this post answers your question, please click "Mark As Answer". If this post is helpful please click "Mark as Helpful".
Saturday, September 10, 2011 4:45 PM
using System;
using System.Collections;
using System.Reflection;
namespace Microsoft.Research.Kinect.Nui
{
public class JointsCollection : IEnumerable
{
public int Count { get; }
public Joint this[JointID i] { get; set; }
public IEnumerator GetEnumerator();
}
}
Sorry! How do I see the InnerException? The Joint seems to have Non-Public Member. But I cannot modify the Joint Class.
akira32 編程之家 Yahoo http://tw.myblog.yahoo.com/akira32-akira32
Saturday, September 10, 2011 5:34 PM
akira32,
Are you using a yield return to return your collection? if so I believe that would make it not serializable.
Also, does the Join class have a parameterless default public constructor? The XMLSerializer will complain about this if it doesn't (which you can see in the inner exception).
Tom Overton
Sunday, September 11, 2011 1:31 AM
If JointCollection does not have a public parameterless constructor, it will not be xml serializable. Try adding a default constructor as below:
public JointsCollection() {}
--
Mike
Sunday, September 11, 2011 11:03 AM
JointCollection also does not have public member variables.akira32 編程之家 Yahoo http://tw.myblog.yahoo.com/akira32-akira32
Sunday, September 11, 2011 11:35 AM
The fact of whether a class has public member variables would not prevent a class from being XmlSerialized.
Because of this, I am unsure of what your last post is trying to state.
--
Mike
Sunday, September 11, 2011 12:13 PM
JointCollection also does not have public member variables.
That wouldn't make a difference. It's the fact that JointCollection (and maybe Joint) classes don't have a parameterless public constructor that's most likely the cause of the serialization error.Tom Overton
Monday, September 12, 2011 10:53 AM
Does XML Serialize only export the public member variables?akira32 編程之家 Yahoo http://tw.myblog.yahoo.com/akira32-akira32