Deserialize inside visual studio


#1

If I have added byte[] file MakaBreps.bin in Visual Studio resources, how can I deserialize it?

Before I followed this grasshopper reference:

But this example works with directories and folders.
I am wondering how it would work if I have the .bin file in project properties.resources?

What I have so far in code:

        protected override void SolveInstance(IGH_DataAccess DA) {

        //////////////////////////////////////////////////

        // Serialized data will write using the current version of Rhino
        // If you want to write data in Rhino 5 that can be read into Rhino 4,
        // then you need to use the SerializationOptions class to enforce this

        var options = new Rhino.FileIO.SerializationOptions();
        options.RhinoVersion = 4;
        var context = new System.Runtime.Serialization.StreamingContext(System.Runtime.Serialization.StreamingContextStates.All, options);
        var bin_formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(null, context);

     //From here I am lost
        bin_formatter.Deserialize(Properties.Resources.MakaBreps);

        //stream.Close();
    }

(Dale Fugier) #2

Hi @Petras_Vestartas,

See if the attached sample project helps.

SampleCsDeseializeEmbeddedResource.zip (13.0 KB)

– Dale