binary-serialization

When should I use XML Serialization vs. Binary Serialization in the .NET framework?

一笑奈何 提交于 2019-11-30 08:26:14
I'm confused - when should I be using XML Serialization and when should I be using Binary Serialization in the .NET framework? Adeel Specific to .NET, If you have two applications that are using the same type system, then you can use binary serialization. On the other hand if you have applications that are in different platforms then it is recommended to use XML Serialization. So if i am writing a chat application (client and server), I might use binary serialization, but if I later decide that I should use Python to write a client, then I may not. Marc Gravell Both of the existing answers

BinaryFormatter.Deserialize “unable to find assembly” after ILMerge

為{幸葍}努か 提交于 2019-11-30 05:04:39
I have a C# solution with a referenced dll (also C# with the same .Net version). When I build the solution and run the resulting exe, without merging the exe and the referenced dll, everything works fine. Now I want to merge these into one exe. I run ILMerge and everything appears to work ok. I try to execute the exe and it seems to run just fine until it tries to deserialize an object defined in the referenced dll. using (Stream fstream = new FileStream(file_path, FileMode.Open)) { BinaryFormatter bf = new BinaryFormatter(); return bf.Deserialize(fstream) as ControlledRuleCollection; //

Convert a byte[] array into DataTable

别来无恙 提交于 2019-11-29 22:16:21
问题 I saved an object of type DataTable into SQL 2005 database in a field of type varbinary. I want to retrieve it back but I wasn't able to type cast it. This is how i saved it. MemoryStream memStream = new MemoryStream(); StreamWriter sw = new StreamWriter(memStream); sw.Write(dt); con.Open(); using (SqlCommand cmd = new SqlCommand("INSERT INTO Tables(TableName, TableData, QuestionID) VALUES (@TableName, @TableData, @QuestionID)", con)) { cmd.Parameters.Add("@TableName", SqlDbType.VarChar)

When should I use XML Serialization vs. Binary Serialization in the .NET framework?

▼魔方 西西 提交于 2019-11-29 12:29:20
问题 I'm confused - when should I be using XML Serialization and when should I be using Binary Serialization in the .NET framework? 回答1: Specific to .NET, If you have two applications that are using the same type system, then you can use binary serialization. On the other hand if you have applications that are in different platforms then it is recommended to use XML Serialization. So if i am writing a chat application (client and server), I might use binary serialization, but if I later decide

How to write to file when using Marshal::dump in Ruby for object serialization

≯℡__Kan透↙ 提交于 2019-11-29 05:18:35
Lets say I have the object line from class Line : class Line def initialize point1, point2 @p1 = point1 @p2 = point2 end end line = Line.new... How can I binary serialize the line object? I tried with: data = Marshal::dump(line, "path/to/still/unexisting/file") but it created file and didn't add anything. I read the Class: IO documentation but I couldn't really get it. Like this: class Line attr_reader :p1, :p2 def initialize point1, point2 @p1 = point1 @p2 = point2 end end line = Line.new([1,2], [3,4]) Save line : FNAME = 'my_file' File.open(FNAME, 'wb') {|f| f.write(Marshal.dump(line))}

BinaryFormatter.Deserialize “unable to find assembly” after ILMerge

依然范特西╮ 提交于 2019-11-29 02:50:13
问题 I have a C# solution with a referenced dll (also C# with the same .Net version). When I build the solution and run the resulting exe, without merging the exe and the referenced dll, everything works fine. Now I want to merge these into one exe. I run ILMerge and everything appears to work ok. I try to execute the exe and it seems to run just fine until it tries to deserialize an object defined in the referenced dll. using (Stream fstream = new FileStream(file_path, FileMode.Open)) {

Boost Serialization Binary Archive giving incorrect output

放肆的年华 提交于 2019-11-28 14:24:41
I am trying to Serialize a class. Class definition: class StartPeerSessionRequest { public: StartPeerSessionRequest(); virtual ~StartPeerSessionRequest(); void composeRequestwithHardCodeValues(); void save(); stringstream serializedRequest; /*boost::serialization::binary_object serlreq;*/ private: StartPeerSessionRequest(const StartPeerSessionRequest &); uint16_t mProtocolVersion; uint16_t mSessionFlags; uint16_t mMaxResponseLength; string mMake; string mModel; string mSerialNumber; uint8_t mTrackDelay; string mHeadUnitModel; string mCarModelYear; string mVin; uint16_t mVehicleMileage; uint8_t

How to analyse contents of binary serialization stream?

瘦欲@ 提交于 2019-11-27 17:51:25
I'm using binary serialization (BinaryFormatter) as a temporary mechanism to store state information in a file for a relatively complex (game) object structure; the files are coming out much larger than I expect, and my data structure includes recursive references - so I'm wondering whether the BinaryFormatter is actually storing multiple copies of the same objects, or whether my basic "number of objects and values I should have" arithmentic is way off-base, or where else the excessive size is coming from. Searching on stack overflow I was able to find the specification for Microsoft's binary

How to create a SerializationBinder for the Binary Formatter that handles the moving of types from one assembly and namespace to another

你说的曾经没有我的故事 提交于 2019-11-27 09:29:09
The context is as follows I want to refactor code by moving it around to different projects Some of this code comprises of serializable DTOs that are used to send and receive data across multiple endpoints If I move the code around, serialization breaks (therefore it is not backward compatible with older versions of my application) A solution to this problem is the SerializationBinder which allows me to "redirect" in a sense from one type to another. I therefore want to create a SerializationBinder to meet this need. However it must do so by meeting the following requirements The inputs to the

Boost Serialization Binary Archive giving incorrect output

若如初见. 提交于 2019-11-27 08:33:53
问题 I am trying to Serialize a class. Class definition: class StartPeerSessionRequest { public: StartPeerSessionRequest(); virtual ~StartPeerSessionRequest(); void composeRequestwithHardCodeValues(); void save(); stringstream serializedRequest; /*boost::serialization::binary_object serlreq;*/ private: StartPeerSessionRequest(const StartPeerSessionRequest &); uint16_t mProtocolVersion; uint16_t mSessionFlags; uint16_t mMaxResponseLength; string mMake; string mModel; string mSerialNumber; uint8_t