Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ C# MFC
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... Smile | :)
 
Renjith
Posted 6-Feb-13 0:55am
Comments
aspnet_regiis -i at 6-Feb-13 6:58am
   
Not possible
sjelen at 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
good
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.
  Permalink  
Comments
Renjith.K.C at 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 at 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
0 OriginalGriff 310
1 Sergey Alexandrovich Kryukov 202
2 Richard MacCutchan 160
3 PhilLenoir 154
4 Sharmanuj 146
0 Sergey Alexandrovich Kryukov 5,999
1 OriginalGriff 5,115
2 CPallini 2,473
3 Richard MacCutchan 1,597
4 Abhinav S 1,505


Advertise | Privacy | Mobile
Web04 | 2.8.140814.1 | Last Updated 6 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

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