there was an error reflecting type (by XmlSerializer) (base on SkeletalViewer sample)

已答复 there was an error reflecting type (by XmlSerializer) (base on SkeletalViewer sample)

  • Saturday, September 10, 2011 2:38 PM
     
      Has Code

    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

  • Monday, September 12, 2011 7:15 PM
    Owner
     
     Answered

    Akira32,

    When running this code, the full exception message gives you the answer as to why this is not possible:

    System.InvalidOperationException: There was an error reflecting type 'SkeletalViewer.MainWindow.KinectJointCollection'. ---> System.InvalidOperationException: To be XML serializable, types which inherit from IEnumerable must have an implementation of Add(System.Object) at all levels of their inheritance hierarchy. Microsoft.Research.Kinect.Nui.JointsCollection does not implement Add(System.Object).

    So, to work around this limitation, you would have to create your own structure that mirrors JointsCollection, but in a serializable way. Sorry for the inconvenience, though, and thanks for the feedback.

    Eddy


    I'm here to help
  • Tuesday, September 13, 2011 2:54 PM
     
     

    Sorry! Where can I see the message as below:

    System.InvalidOperationException:To be XML serializable, types which inherit from IEnumerable must have an implementation of Add(System.Object) at all levels of their inheritance hierarchy. Microsoft.Research.Kinect.Nui.JointsCollection does not implement Add(System.Object).


    akira32 編程之家 Yahoo http://tw.myblog.yahoo.com/akira32-akira32
  • Tuesday, September 13, 2011 4:26 PM
    Owner
     
     

    when I ran the application in debug mode and stepped through line by line. When calling the XmlSerializer the debugger reported that an exception was thrown, and then when I clicked on dialog to show exception details I could see this additional detail for exception. Also, you could add a try/catch block around code causing exception, and the catch statement will have an instance of exception object that you can examine for more details in the debugger, or you could just do "System.Console.Write(e);" where 'e' is a variable of type "Exception".

    Eddy


    I'm here to help