473,791 Members | 2,861 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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<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
Aug 27 '08 #1
6 7543
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:
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****@microsof t.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.comwr ote in message
news:IO******** ******@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:
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****@microsof t.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****@microsof t.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.comwr ote in message
news:DM******** ******@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 (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****@microsof t.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.comwr ote in message
news:DM******** ******@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 (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****@microsof t.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*******@noem ail.noemailwrot e in message
news:u2******** ******@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

Sep 30 '08 #7

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

Similar topics

3
1664
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 the ICollection interface, this causes the deserialization to fail. In my case this is a huge problem, and any suggestion for a workaround would be happily received. A small example of a set of classes that reproduces the problem is included
4
3156
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" xmlns:someobj=http://www.abcinc.com/objectdefinition> ...... </SomeObject>
3
9796
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 (when I check the database the field that holds the binary data seems populated), but when I want to deserialize this same byte array the application fails and gives me the following error: Binary stream does not contain a valid BinaryHeader, 0...
3
2462
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 the data in the file, I wonder is it possible to read files in this manner ( e.g. custom implementation of the ISerializable interface )? is this right way to extract data from the file? OR should I rather 'manually' use the FileStream to read...
3
9796
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 response. As a result of seraching news groups I guessed that the SOAP response defines an array element in a way that causes the dotnet deserialization routines to put the content in a generic object array (object) BUT the content is supposed to...
1
3752
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 that accesses a Axis provided web service. The client uses the code generated, using wsdl.exe, from the wsdl file provided by the web service provider. The web response has the following schema (roughly):
5
5535
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 response is null instead of being populated. The SOAP response from the service looks good and I cannot see anything wrong with the WSDL or XML schema. How do I get .NET to tell me what it doesn't like? Is there a way to turn on some kind of tracing...
12
7768
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. thanks josh
3
5000
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 implementations cannot be serialized, I had to take matters into my own hands by implementing a wrapper over the Hashtable which implemted IXmlSerializable. I called it XmlHashtable. It has, among other convenience methods, a method
0
1049
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 use the web service in windows forms all properties are set to NULL. Is there any deserialization issue with Generics in webservices. Appreciate any inputs .. Thanks
0
10426
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10154
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9993
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7537
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5558
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4109
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3713
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.