Deserialization issue

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Joe

    Deserialization issue

    I'm getting an error when deserializing my objects:
    "The ObjectManager found an invalid number of fixups. This usually indicates
    a problem in the Formatter."

    I added a new object to a class that gets serialized and put the
    OptionalField attribute on that object. When trying to deserialize my object
    in an older version of our application that doesn't have this new class I
    get the above error but that's only when items have been added to the class.

    The class looks like this:
    public class MyCollection : BindingList<MyC lass>
    {

    }

    public class MyClass
    {
    private string mystring;
    private CustomEnum myenum1;
    private CustomEnum2 myenum2;
    }

    public class ClassThatGetsSe rialized
    {
    string member1;
    int member2;
    ...
    ...
    [OptionalField]
    MyCollection mycollection;

    ....
    }

    The error only occurs if object ClassThatGetsSe rialized is deserialized by
    an older version that doesn't have the definition for MyCollection and if
    the member of ClassThatGetsSe rialized.mycoll ection has items in it. If there
    are no items then the error does not happen.

    We use the OptionalField attribute in many places and it always works fine.

    Any ideas?

    Thanks,
    Joe


  • Jialiang Ge [MSFT]

    #2
    RE: Deserialization issue

    Hello Joe,

    Thank you for reporting this issue to us. I've reproduced the symptom on my
    side with your instructions:

    **** App that serialize the object ****

    [Serializable]
    public class MyCollection : BindingList<MyC lass>
    {
    }
    [Serializable]
    public class MyClass
    {
    private string mystring = "test";
    }
    [Serializable()]
    class ClassThatGetsSe rialized
    {
    public ClassThatGetsSe rialized()
    {
    mycollection.Ad d(new MyClass());
    }

    [OptionalField]
    MyCollection mycollection = new MyCollection();

    public void Save()
    {
    System.IO.FileS tream oStream = new
    System.IO.FileS tream("c:\\test .txt",
    System.IO.FileM ode.Create);

    IFormatter oFormatter = (IFormatter)new BinaryFormatter ();
    oFormatter.Seri alize(oStream, this);
    oStream.Close() ;
    }
    }

    ClassThatGetsSe rialized obj = new ClassThatGetsSe rialized();
    obj.Save();

    **** App that deserialize the object ****

    [Serializable()]
    class ClassThatGetsSe rialized
    {
    public static ClassThatGetsSe rialized LoadObject()
    {
    System.IO.FileS tream oStream = new
    System.IO.FileS tream("c:\\test .txt",
    System.IO.FileM ode.Open);
    IFormatter oFormatter = (IFormatter)new BinaryFormatter ();
    ClassThatGetsSe rialized obj =
    (ClassThatGetsS erialized)oForm atter.Deseriali ze(oStream);
    oStream.Close() ;
    return obj;
    }
    }

    ClassThatGetsSe rialized obj = ClassThatGetsSe rialized.LoadOb ject();

    When I run the Deserialization app after running the Serialization one, I
    get the exception "The ObjectManager found an invalid number of fixups.
    This usually indicates a problem in the Formatter". The callstack is:

    at System.Runtime. Serialization.O bjectManager.Do Fixups()
    at
    System.Runtime. Serialization.F ormatters.Binar y.ObjectReader. Deserialize(Hea d
    erHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean
    isCrossAppDomai n, IMethodCallMess age methodCallMessa ge)
    at
    System.Runtime. Serialization.F ormatters.Binar y.BinaryFormatt er.Deserialize( S
    tream serializationSt ream, HeaderHandler handler, Boolean fCheck, Boolean
    isCrossAppDomai n, IMethodCallMess age methodCallMessa ge)
    at
    System.Runtime. Serialization.F ormatters.Binar y.BinaryFormatt er.Deserialize( S
    tream serializationSt ream)
    at ConsoleApplicat ion1.ClassThatG etsSerialized.L oadObject()
    at ConsoleApplicat ion1.Program.Ma in(String[] args)

    Joe, I suggest your submitting this issue to our feedback site, where the
    product group will further look into it:

    It's appreciated if you paste the feedback link here to benefit the
    community.

    Thanks
    Jialiang Ge (jialge@online. microsoft.com, remove 'online.')
    Microsoft Online Community Support

    =============== =============== =============== ====
    Delighting our customers is our #1 priority. We welcome your comments and
    suggestions about how we can improve the support we provide to you. Please
    feel free to let my manager know what you think of the level of service
    provided. You can send feedback directly to my manager at:
    msdnmg@microsof t.com.

    This posting is provided "AS IS" with no warranties, and confers no rights.
    =============== =============== =============== ====

    Comment

    • Joe

      #3
      Re: Deserialization issue

      Are there any workarounds for this?

      ""Jialiang Ge [MSFT]"" <jialge@online. microsoft.comwr ote in message
      news:IOezNrNCJH A.1768@TK2MSFTN GHUB02.phx.gbl. ..
      Hello Joe,
      >
      Thank you for reporting this issue to us. I've reproduced the symptom on
      my
      side with your instructions:
      >
      **** App that serialize the object ****
      >
      [Serializable]
      public class MyCollection : BindingList<MyC lass>
      {
      }
      [Serializable]
      public class MyClass
      {
      private string mystring = "test";
      }
      [Serializable()]
      class ClassThatGetsSe rialized
      {
      public ClassThatGetsSe rialized()
      {
      mycollection.Ad d(new MyClass());
      }
      >
      [OptionalField]
      MyCollection mycollection = new MyCollection();
      >
      public void Save()
      {
      System.IO.FileS tream oStream = new
      System.IO.FileS tream("c:\\test .txt",
      System.IO.FileM ode.Create);
      >
      IFormatter oFormatter = (IFormatter)new BinaryFormatter ();
      oFormatter.Seri alize(oStream, this);
      oStream.Close() ;
      }
      }
      >
      ClassThatGetsSe rialized obj = new ClassThatGetsSe rialized();
      obj.Save();
      >
      **** App that deserialize the object ****
      >
      [Serializable()]
      class ClassThatGetsSe rialized
      {
      public static ClassThatGetsSe rialized LoadObject()
      {
      System.IO.FileS tream oStream = new
      System.IO.FileS tream("c:\\test .txt",
      System.IO.FileM ode.Open);
      IFormatter oFormatter = (IFormatter)new BinaryFormatter ();
      ClassThatGetsSe rialized obj =
      (ClassThatGetsS erialized)oForm atter.Deseriali ze(oStream);
      oStream.Close() ;
      return obj;
      }
      }
      >
      ClassThatGetsSe rialized obj = ClassThatGetsSe rialized.LoadOb ject();
      >
      When I run the Deserialization app after running the Serialization one, I
      get the exception "The ObjectManager found an invalid number of fixups.
      This usually indicates a problem in the Formatter". The callstack is:
      >
      at System.Runtime. Serialization.O bjectManager.Do Fixups()
      at
      System.Runtime. Serialization.F ormatters.Binar y.ObjectReader. Deserialize(Hea d
      erHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean
      isCrossAppDomai n, IMethodCallMess age methodCallMessa ge)
      at
      System.Runtime. Serialization.F ormatters.Binar y.BinaryFormatt er.Deserialize( S
      tream serializationSt ream, HeaderHandler handler, Boolean fCheck, Boolean
      isCrossAppDomai n, IMethodCallMess age methodCallMessa ge)
      at
      System.Runtime. Serialization.F ormatters.Binar y.BinaryFormatt er.Deserialize( S
      tream serializationSt ream)
      at ConsoleApplicat ion1.ClassThatG etsSerialized.L oadObject()
      at ConsoleApplicat ion1.Program.Ma in(String[] args)
      >
      Joe, I suggest your submitting this issue to our feedback site, where the
      product group will further look into it:

      It's appreciated if you paste the feedback link here to benefit the
      community.
      >
      Thanks
      Jialiang Ge (jialge@online. microsoft.com, remove 'online.')
      Microsoft Online Community Support
      >
      =============== =============== =============== ====
      Delighting our customers is our #1 priority. We welcome your comments and
      suggestions about how we can improve the support we provide to you. Please
      feel free to let my manager know what you think of the level of service
      provided. You can send feedback directly to my manager at:
      msdnmg@microsof t.com.
      >
      This posting is provided "AS IS" with no warranties, and confers no
      rights.
      =============== =============== =============== ====
      >

      Comment

      • Jialiang Ge [MSFT]

        #4
        Re: Deserialization issue

        Hello Joe,

        The old client app expects to know the type of MyClass.
        I find that a possible workaround in this issue is to declare MyClass as a
        struct (value type), instead of a class:

        public struct MyClass
        {
        private string mystring;
        private CustomEnum myenum1;
        private CustomEnum2 myenum2;
        }

        In this way, the old apps continue working fine. Please have a try and let
        me know whether the workaround is helpful to you.

        Have a nice weekend!

        Regards,
        Jialiang Ge (jialge@online. microsoft.com, remove 'online.')
        Microsoft Online Community Support

        =============== =============== =============== ====
        Delighting our customers is our #1 priority. We welcome your comments and
        suggestions about how we can improve the support we provide to you. Please
        feel free to let my manager know what you think of the level of service
        provided. You can send feedback directly to my manager at:
        msdnmg@microsof t.com.

        This posting is provided "AS IS" with no warranties, and confers no rights.
        =============== =============== =============== ====

        Comment

        • Joe

          #5
          Re: Deserialization issue

          Making it a struct and re-saving the files seems to have worked.
          Thanks.

          ""Jialiang Ge [MSFT]"" <jialge@online. microsoft.comwr ote in message
          news:DMiCK$YCJH A.4896@TK2MSFTN GHUB02.phx.gbl. ..
          Hello Joe,
          >
          The old client app expects to know the type of MyClass.
          I find that a possible workaround in this issue is to declare MyClass as a
          struct (value type), instead of a class:
          >
          public struct MyClass
          {
          private string mystring;
          private CustomEnum myenum1;
          private CustomEnum2 myenum2;
          }
          >
          In this way, the old apps continue working fine. Please have a try and let
          me know whether the workaround is helpful to you.
          >
          Have a nice weekend!
          >
          Regards,
          Jialiang Ge (jialge@online. microsoft.com, remove 'online.')
          Microsoft Online Community Support
          >
          =============== =============== =============== ====
          Delighting our customers is our #1 priority. We welcome your comments and
          suggestions about how we can improve the support we provide to you. Please
          feel free to let my manager know what you think of the level of service
          provided. You can send feedback directly to my manager at:
          msdnmg@microsof t.com.
          >
          This posting is provided "AS IS" with no warranties, and confers no
          rights.
          =============== =============== =============== ====
          >

          Comment

          • Joe

            #6
            Re: Deserialization issue

            Sorry about taking so long to get back.

            Using a struct only sort of works. It does not make it easy for data binding
            to a data grid.


            ""Jialiang Ge [MSFT]"" <jialge@online. microsoft.comwr ote in message
            news:DMiCK$YCJH A.4896@TK2MSFTN GHUB02.phx.gbl. ..
            Hello Joe,
            >
            The old client app expects to know the type of MyClass.
            I find that a possible workaround in this issue is to declare MyClass as a
            struct (value type), instead of a class:
            >
            public struct MyClass
            {
            private string mystring;
            private CustomEnum myenum1;
            private CustomEnum2 myenum2;
            }
            >
            In this way, the old apps continue working fine. Please have a try and let
            me know whether the workaround is helpful to you.
            >
            Have a nice weekend!
            >
            Regards,
            Jialiang Ge (jialge@online. microsoft.com, remove 'online.')
            Microsoft Online Community Support
            >
            =============== =============== =============== ====
            Delighting our customers is our #1 priority. We welcome your comments and
            suggestions about how we can improve the support we provide to you. Please
            feel free to let my manager know what you think of the level of service
            provided. You can send feedback directly to my manager at:
            msdnmg@microsof t.com.
            >
            This posting is provided "AS IS" with no warranties, and confers no
            rights.
            =============== =============== =============== ====
            >

            Comment

            • Joe

              #7
              Re: Deserialization issue

              My solution was to re-write MyCollection class as MyCollection :
              CollectionBase, IBindingList.

              "Joe" <jbassking@noem ail.noemailwrot e in message
              news:u2cNbuGCJH A.3348@TK2MSFTN GP04.phx.gbl...
              I'm getting an error when deserializing my objects:
              "The ObjectManager found an invalid number of fixups. This usually
              indicates a problem in the Formatter."
              >
              I added a new object to a class that gets serialized and put the
              OptionalField attribute on that object. When trying to deserialize my
              object in an older version of our application that doesn't have this new
              class I get the above error but that's only when items have been added to
              the class.
              >
              The class looks like this:
              public class MyCollection : BindingList<MyC lass>
              {
              >
              }
              >
              public class MyClass
              {
              private string mystring;
              private CustomEnum myenum1;
              private CustomEnum2 myenum2;
              }
              >
              public class ClassThatGetsSe rialized
              {
              string member1;
              int member2;
              ...
              ...
              [OptionalField]
              MyCollection mycollection;
              >
              ....
              }
              >
              The error only occurs if object ClassThatGetsSe rialized is deserialized by
              an older version that doesn't have the definition for MyCollection and if
              the member of ClassThatGetsSe rialized.mycoll ection has items in it. If
              there are no items then the error does not happen.
              >
              We use the OptionalField attribute in many places and it always works
              fine.
              >
              Any ideas?
              >
              Thanks,
              Joe
              >

              Comment

              Working...