Binary serialization

Binary serialization

Anonymous
Not applicable
906 Views
2 Replies
Message 1 of 3

Binary serialization

Anonymous
Not applicable

Hi Everybody,

 

I am trying to serialize in binaray way a Parameter in a files, not in .RVT file. However, it does not work on. The code is very simple

 

                    using (Stream stream = File.Open(dialog.FileName, FileMode.Open))
                    {
                        BinaryFormatter bin = new BinaryFormatter();
           
                        bin.Serialize(stream, parameter);

 

                        stream.Close();
                    }

 

 

where parameter is an instance of Parameter class. Now I am using instance of Parameter class, but later, I will serialize other class of the API, for example Element, Level, Phase,..

 

Any could help please?

 

Javi

 

0 Likes
907 Views
2 Replies
Replies (2)
Message 2 of 3

jeremytammik
Autodesk
Autodesk

Dear Javi,

 

Regarding how to use the .NET serialisation functionality, I would suggest that you look at the corresponding .NET forums.

 

The issue here may be that you are serialising an object stored in the variable 'parameter'.

 

You do not let us know what this variable actually contains, what data type it has, etc.

 

I would suspect that you are passing in a Revit Parameter object instance.

 

That will probably not work, since .NET has no idea how you would like that data to be serialised.

 

You will probably fare better if you first extract the data from the parameter and format it in the manner you prefer, e.g. into a string variable.

 

Then pass the string value to the serialisation.

 

I would also strongly recommend that you always debug your code, i.e., step through it statement by statement in the debugger and watch what it does.

 

Then this kind of problem will immediately become clear to you and you will save yourself the rest of the universe many questions and many hours of head scratching.

 

I hope this helps.

 

Cheers,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 3

Anonymous
Not applicable

Thanks for your answer. At the end, I realize that I could not serialize in a direct way an objet of REVIT. The way I will use it is convert the Id in a integer an serialize it.

0 Likes