Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. Serializable And Deserialize

Serializable And Deserialize

Scheduled Pinned Locked Moved Managed C++/CLI
tutorial
15 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J javad_2005

    when i Serialize Object in My Application int the FileStream I can't Deserialize FileStream in Other Application . so how To Serialize Object in fileStream into My Application And Deserialize FileStream in other Application

    M Offline
    M Offline
    Mark Salsbery
    wrote on last edited by
    #6

    Did you ever get this working? Mark

    Mark Salsbery Microsoft MVP - Visual C++ :java:

    J 1 Reply Last reply
    0
    • M Mark Salsbery

      Did you ever get this working? Mark

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      J Offline
      J Offline
      javad_2005
      wrote on last edited by
      #7

      I can Serialize And Deserialize In One Application . i workinn Server And client Application so i need Send Struct to Client when i serialize Struct and Send , in client Application can't Deserialize Struct

      M G 2 Replies Last reply
      0
      • J javad_2005

        I can Serialize And Deserialize In One Application . i workinn Server And client Application so i need Send Struct to Client when i serialize Struct and Send , in client Application can't Deserialize Struct

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #8

        The problem is, the same assembly needs to be used to deserialize as the one that serialized it. There's ways around this though, if you don't want to keep a separate assembly to maintain on both ends. Please post the EXACT exception message (entirely) and I'll show you an example...If you'd like. You can get the message from the exception by wrapping your deserialize code in a try block and adding something like

        ...  
        catch ( SerializationException^ e )
            {
                Console::WriteLine( "Failed to deserialize. Reason: {0}", e->Message );
                //throw;
            }

        Mark

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        J 1 Reply Last reply
        0
        • J javad_2005

          I can Serialize And Deserialize In One Application . i workinn Server And client Application so i need Send Struct to Client when i serialize Struct and Send , in client Application can't Deserialize Struct

          G Offline
          G Offline
          Giorgi Dalakishvili
          wrote on last edited by
          #9

          In order to serialize in one assembly and deserialize in another either you need to maintain same assembly in both applications or you use a technique described here: Advanced Binary Serialization: Deserializing an Object Into a Different Type Than the One It was Serialized Into[^] The example is in c# but you should be able to use the same principle in C++ .Net too. Hope it helps.

          #region signature my articles #endregion

          M J 2 Replies Last reply
          0
          • G Giorgi Dalakishvili

            In order to serialize in one assembly and deserialize in another either you need to maintain same assembly in both applications or you use a technique described here: Advanced Binary Serialization: Deserializing an Object Into a Different Type Than the One It was Serialized Into[^] The example is in c# but you should be able to use the same principle in C++ .Net too. Hope it helps.

            #region signature my articles #endregion

            M Offline
            M Offline
            Mark Salsbery
            wrote on last edited by
            #10

            Good article Giorgi! Mark

            Mark Salsbery Microsoft MVP - Visual C++ :java:

            G 1 Reply Last reply
            0
            • M Mark Salsbery

              Good article Giorgi! Mark

              Mark Salsbery Microsoft MVP - Visual C++ :java:

              G Offline
              G Offline
              Giorgi Dalakishvili
              wrote on last edited by
              #11

              Thanks Mark :)

              #region signature my articles #endregion

              1 Reply Last reply
              0
              • M Mark Salsbery

                The problem is, the same assembly needs to be used to deserialize as the one that serialized it. There's ways around this though, if you don't want to keep a separate assembly to maintain on both ends. Please post the EXACT exception message (entirely) and I'll show you an example...If you'd like. You can get the message from the exception by wrapping your deserialize code in a try block and adding something like

                ...  
                catch ( SerializationException^ e )
                    {
                        Console::WriteLine( "Failed to deserialize. Reason: {0}", e->Message );
                        //throw;
                    }

                Mark

                Mark Salsbery Microsoft MVP - Visual C++ :java:

                J Offline
                J Offline
                javad_2005
                wrote on last edited by
                #12

                in SerializeApp : [SerializableAttribute] ref struct MyStruct { int n; int j; }; MyStruct ^my=gcnew MyStruct; my->j=1; my->n=1; FileStream ^file=gcnew FileStream("c:\\Test.dat",FileMode::Create); BinaryFormatter ^formatter=gcnew BinaryFormatter; formatter->Serialize(file,my); /////////////////////////////////////////// In DeserializeApp : FileStream ^file=gcnew FileStream("c:\\Test.dat",FileMode::Open); BinaryFormatter ^formatter=gcnew BinaryFormatter; try { MyStruct ^my=(MyStruct ^)formatter->Deserialize(file); } catch (SerializationException^ e) { textBox1->Text=e->Message; } Error: Unable to find assembly 'SerializeApp, Version=1.0.2987.23837, Culture=neutral, PublicKeyToken=null'.

                1 Reply Last reply
                0
                • G Giorgi Dalakishvili

                  In order to serialize in one assembly and deserialize in another either you need to maintain same assembly in both applications or you use a technique described here: Advanced Binary Serialization: Deserializing an Object Into a Different Type Than the One It was Serialized Into[^] The example is in c# but you should be able to use the same principle in C++ .Net too. Hope it helps.

                  #region signature my articles #endregion

                  J Offline
                  J Offline
                  javad_2005
                  wrote on last edited by
                  #13

                  Thnak's and Very Good

                  G 1 Reply Last reply
                  0
                  • J javad_2005

                    Thnak's and Very Good

                    G Offline
                    G Offline
                    Giorgi Dalakishvili
                    wrote on last edited by
                    #14

                    You are welcome :)

                    #region signature my articles #endregion

                    J 1 Reply Last reply
                    0
                    • G Giorgi Dalakishvili

                      You are welcome :)

                      #region signature my articles #endregion

                      J Offline
                      J Offline
                      javad_2005
                      wrote on last edited by
                      #15

                      When I Seriliaze Object In the File how To save Assembly Name And Typename with My self

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups