Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

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... :)

Renjith
Posted
Comments
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

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.
 
Share this answer
 
Comments
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900