473,396 Members | 1,871 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Deserialization issue

Joe
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<MyClass>
{

}

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

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

....
}

The error only occurs if object ClassThatGetsSerialized is deserialized by
an older version that doesn't have the definition for MyCollection and if
the member of ClassThatGetsSerialized.mycollection 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
Aug 27 '08 #1
6 7479
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<MyClass>
{
}
[Serializable]
public class MyClass
{
private string mystring = "test";
}
[Serializable()]
class ClassThatGetsSerialized
{
public ClassThatGetsSerialized()
{
mycollection.Add(new MyClass());
}

[OptionalField]
MyCollection mycollection = new MyCollection();

public void Save()
{
System.IO.FileStream oStream = new
System.IO.FileStream("c:\\test.txt",
System.IO.FileMode.Create);

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

ClassThatGetsSerialized obj = new ClassThatGetsSerialized();
obj.Save();

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

[Serializable()]
class ClassThatGetsSerialized
{
public static ClassThatGetsSerialized LoadObject()
{
System.IO.FileStream oStream = new
System.IO.FileStream("c:\\test.txt",
System.IO.FileMode.Open);
IFormatter oFormatter = (IFormatter)new BinaryFormatter();
ClassThatGetsSerialized obj =
(ClassThatGetsSerialized)oFormatter.Deserialize(oS tream);
oStream.Close();
return obj;
}
}

ClassThatGetsSerialized obj = ClassThatGetsSerialized.LoadObject();

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.ObjectManager.DoFixup s()
at
System.Runtime.Serialization.Formatters.Binary.Obj ectReader.Deserialize(Head
erHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean
isCrossAppDomain, IMethodCallMessage methodCallMessage)
at
System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter.Deserialize(S
tream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean
isCrossAppDomain, IMethodCallMessage methodCallMessage)
at
System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter.Deserialize(S
tream serializationStream)
at ConsoleApplication1.ClassThatGetsSerialized.LoadOb ject()
at ConsoleApplication1.Program.Main(String[] args)

Joe, I suggest your submitting this issue to our feedback site, where the
product group will further look into it:
http://connect.microsoft.com/VisualStudio
It's appreciated if you paste the feedback link here to benefit the
community.

Thanks
Jialiang Ge (ji****@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:
ms****@microsoft.com.

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

Aug 28 '08 #2
Joe
Are there any workarounds for this?

""Jialiang Ge [MSFT]"" <ji****@online.microsoft.comwrote in message
news:IO**************@TK2MSFTNGHUB02.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<MyClass>
{
}
[Serializable]
public class MyClass
{
private string mystring = "test";
}
[Serializable()]
class ClassThatGetsSerialized
{
public ClassThatGetsSerialized()
{
mycollection.Add(new MyClass());
}

[OptionalField]
MyCollection mycollection = new MyCollection();

public void Save()
{
System.IO.FileStream oStream = new
System.IO.FileStream("c:\\test.txt",
System.IO.FileMode.Create);

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

ClassThatGetsSerialized obj = new ClassThatGetsSerialized();
obj.Save();

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

[Serializable()]
class ClassThatGetsSerialized
{
public static ClassThatGetsSerialized LoadObject()
{
System.IO.FileStream oStream = new
System.IO.FileStream("c:\\test.txt",
System.IO.FileMode.Open);
IFormatter oFormatter = (IFormatter)new BinaryFormatter();
ClassThatGetsSerialized obj =
(ClassThatGetsSerialized)oFormatter.Deserialize(oS tream);
oStream.Close();
return obj;
}
}

ClassThatGetsSerialized obj = ClassThatGetsSerialized.LoadObject();

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.ObjectManager.DoFixup s()
at
System.Runtime.Serialization.Formatters.Binary.Obj ectReader.Deserialize(Head
erHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean
isCrossAppDomain, IMethodCallMessage methodCallMessage)
at
System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter.Deserialize(S
tream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean
isCrossAppDomain, IMethodCallMessage methodCallMessage)
at
System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter.Deserialize(S
tream serializationStream)
at ConsoleApplication1.ClassThatGetsSerialized.LoadOb ject()
at ConsoleApplication1.Program.Main(String[] args)

Joe, I suggest your submitting this issue to our feedback site, where the
product group will further look into it:
http://connect.microsoft.com/VisualStudio
It's appreciated if you paste the feedback link here to benefit the
community.

Thanks
Jialiang Ge (ji****@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:
ms****@microsoft.com.

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

Aug 28 '08 #3
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 (ji****@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:
ms****@microsoft.com.

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

Aug 29 '08 #4
Joe
Making it a struct and re-saving the files seems to have worked.
Thanks.

""Jialiang Ge [MSFT]"" <ji****@online.microsoft.comwrote in message
news:DM**************@TK2MSFTNGHUB02.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 (ji****@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:
ms****@microsoft.com.

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

Aug 29 '08 #5
Joe
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]"" <ji****@online.microsoft.comwrote in message
news:DM**************@TK2MSFTNGHUB02.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 (ji****@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:
ms****@microsoft.com.

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

Sep 29 '08 #6
Joe
My solution was to re-write MyCollection class as MyCollection :
CollectionBase, IBindingList.

"Joe" <jb*******@noemail.noemailwrote in message
news:u2**************@TK2MSFTNGP04.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<MyClass>
{

}

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

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

....
}

The error only occurs if object ClassThatGetsSerialized is deserialized by
an older version that doesn't have the definition for MyCollection and if
the member of ClassThatGetsSerialized.mycollection 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

Sep 30 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: TEK | last post by:
There seems to be a bug when deserialization some classes in the .NET framework. If you try to deserialize a class that has a base class that holds a struct with a member that is implementing...
4
by: Mike Sarbu | last post by:
Hello all, I have an XML file like this: <?xml version="1.0" encoding="utf-8"?> <SomeObject xmlns="http://www.abcinc.com/objectdefinition"...
3
by: Amadelle | last post by:
Hi all and thanks in advance for your help, I am having problems deserializing an object which seems to be serializing just fine. I save the byte array of the serialized object in the database...
3
by: Nadav | last post by:
Hi, I have to read files generated by 3rd party application, these files are in a propriotary format ( not generated using the .NET framework ), I want to implement a custom DeSerializer to read...
3
by: parrot toes | last post by:
Summary: I have been trying to make requests of a web service provided by Axis using a dotnet client with code generated by wsdl.exe and have been getting exceptions when trying to process the...
1
by: parrot toes | last post by:
I tried to post this question before, but there was an error when posting. I case it did get posted and in order to avoid duplication, I'll just repost a summary. I have written a dotnet client...
5
by: frustratedWithDotNet | last post by:
Why does .NET not issue messages or throw exceptions if it doesn't like something in the response from a web service?? I am getting a response object, but an array of custom objects within the...
12
by: yoshijg | last post by:
Is there a way to be notified when the deserialization of an XML is complete, like a callback method? I tried the IDeserializationCallback interface, but that doesnt for XML-Deserialization. ...
3
by: John Glover | last post by:
To whoever can help, I've been having a problem with XML deserialization lately. I needed to serialize and deserialze two objects which inherited from Hashtable. Because IDictionary...
0
by: anand sancheti | last post by:
I was trying to return a generic collection on my webmethod. Things work fine If i visit webservice from browser i.e. it shows the proper content of the collection<T> in XML, but when I try to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.