CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 1999
    Location
    France
    Posts
    393

    [RESOLVED] Serialization problem

    Hi all,

    I'm quite new to C# and I have some Xml serialization indeed.

    I have objects define as follows :
    Code:
    public class ObjSub{
         //some data
         public string mySubStr;
         public int mySubInt;
    }
    
    public class ObjMain{
         //some data
         public string myStr;
         public int myInt;
    
         public ObjSub subObj = new ObjSub();
    }
    I deserialize my objects from Xml file:

    Code:
            public static SchedulerTemplateFile Load(string fileName)
            {
                using (StreamReader sw = new StreamReader(fileName))
                {
                    XmlSerializer xmlSerializer = new XmlSerializer(typeof(ObjMain));
    				xmlSerializer.UnknownAttribute += new XmlAttributeEventHandler(Serializer_UnknownAttribute);
    				return (ObjMain)xmlSerializer.Deserialize(sw);
                }
    
            }
    See that I use An UnknowAttribute event handler to get and store unknown attribute if needed.

    Now here is the problem:
    The Unknown attribute handler works well for ObjMain, but is nevver called for ObjSub.

    if for the ObjSub I have the node
    <ObjSub id="1">
    <mySubStr>"SubStr"</mySubStr>
    <mySubInt>"10"</mySubInt>
    </ObjSub>

    I would never have the event telling me about "id" attribute.

    Does anyone already experienced that.

    Many Thanks

  2. #2
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: Serialization problem

    Quote Originally Posted by F.Mayis
    Hi all,

    I'm quite new to C# and I have some Xml serialization indeed.

    I have objects define as follows :
    ...
    I cannot see any code like
    Code:
    [Serializeable(true)]
    on the top of your calls constructors.
    Jonny
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

  3. #3
    Join Date
    Sep 1999
    Location
    France
    Posts
    393

    Re: Serialization problem

    Hi,

    Thanks, I found the problem in fact it was related to properties function on subObj I got a "get" but no "set".

    Thanks for your help!

  4. #4
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: Serialization problem

    Quote Originally Posted by F.Mayis
    Hi,

    Thanks, I found the problem in fact it was related to properties function on subObj I got a "get" but no "set".

    Thanks for your help!
    If your problem is solved please dont forget to sign the post as resolved using the threadtools on top of the page.Thx
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured