Click here to Skip to main content
13,589,772 members
Rate this:
Please Sign up or sign in to vote.
See more:

I have an old application and it's using CArchive to serialize the object to binary file.
Since I have the source code, I know the object structure in C++ format.

However, is it possible to deserialize CArchive object in C# ?

When I try to read using C# FileStream, it fails with error message :
"The input stream is not a valid binary format."

Thanks in advance... :)

Posted 6-Feb-13 0:55am
bbirajdar 6-Feb-13 6:58am
Not possible
sjelen 6-Feb-13 7:44am
You'll need to know the inner workings of CArchive or at least the structure of binary file it creates.
What exactly did you try, that error does not seem to come from FileStream alone?
A code sample would be helpfull.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

It would be possible if you knew the exact format of the serialized data. But I guess, you don't. There is no .NET type that is able to serialize/deserialize CArchive-compatible streams.

On the other hand, you can write a mixed-mode DLL that provides that functionality, acting as a managed wrapper over a CArchive.

And another solution is to write a COM server that provides a COM object that wraps the CArchive.
Renjith.K.C 7-Feb-13 0:14am
Hi Marius,
Thank you very much for your reply. I have the source code of the serialization method implemented, so I guess I know the format of the serialized data (I'm new to MFC, so not sure about this). It will be very helpful if you can provide some code snippet or links for the above mentioned criteria.
Marius Bancila 7-Feb-13 1:37am
Just because you what WHAT you serialize, doesn't mean you now HOW it is serialized. You need to know the complete binary output, if you want to write a C# de-serializer. I would rather consider the other options that I mentioned.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web01 | 2.8.180615.1 | Last Updated 6 Feb 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100