binary-serialization

deserializing a generic list returns null

坚强是说给别人听的谎言 提交于 2019-12-04 07:57:10
I'm de/serializing an object like so: public class myClass : ISerializable { public List<OType> value; public myClass(SerializationInfo info, StreamingContext context) { this.value = (List<OType>)info.GetValue("value", typeof(List<OType>)); } void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) { info.AddValue("value", value, typeof(List<OType>)); } } The object that is in the list does have the Serializable attribute. When serializing, no errors are thrown and the list is never empty, but when deserializing all of my lists are null and I'm not sure why. I'm

Why does Get-Date seem to return DateTime objects, but the BinarySerializer indicate it returns a PSObject?

倾然丶 夕夏残阳落幕 提交于 2019-12-04 03:27:06
问题 Take the simple HashTable: $data = @{ First = 'Justin'; Last = 'Dearing'; StartDate = Get-Date '2002-03-23'; } The key StartDate seems to contain a DateTime. C:\Users\zippy\Documents> $data.StartDate.GetType().FullName System.DateTime However, if I attempt to perform binary serialization on it, I get an exception complaining that PSObject is not serializable. $ms = New-Object System.IO.MemoryStream $bf = New-Object System.Runtime.Serialization.Formatters.Binary.BinaryFormatter $bf.Serialize(

Does protobuf-net have built-in compression for serialization?

三世轮回 提交于 2019-12-03 01:17:46
I was doing some comparison between BinaryFormatter and protobuf-net serializer and was quite pleased with what I found , but what was strange is that protobuf-net managed to serialize the objects into a smaller byte array than what I would get if I just wrote the value of every property into an array of bytes without any metadata. I know protobuf-net supports string interning if you set AsReference to true , but I'm not doing that in this case, so does protobuf-net provide some compression by default? Here's some code you can run to see for yourself: var simpleObject = new SimpleObject { Id =

Serialization problem : System.UnauthorizedAccessException

烂漫一生 提交于 2019-12-02 06:34:33
问题 I am getting this error: An unhandled exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll Additional information: Access to the path 'C:\Users\Storm Kiernan\Desktop(NEW)Archetype Development Kit\Laboratory\Laboratory\bin\x86\Debug\lol.dataf' is denied. From trying to serialize any object via this code: public static void BinarySerialize<T>(this T t, string path) { DirectoryInfo directoryInfo = new DirectoryInfo(path); directoryInfo.EnsureDirectory(); using

.NET Binary Serialize object with references to other objects . . . what happens?

六月ゝ 毕业季﹏ 提交于 2019-12-01 23:49:43
问题 If you have an object instance A that references other objects (for example instances B and C), and you binary serialize A to a file, what happens? Do you now have serialized data that includes A, B and C? How does it work exactly? What will I get if I deserialize the data? A, B, and C?? (Feel free to include internal workings explanations as well). 回答1: All of the references to other objects will be serialized as well. If you deserialize the data, you will end up with a complete, working set

Java partial (de)serialization of objects

主宰稳场 提交于 2019-12-01 22:13:59
Let's say we have 3 Classes: class foo { // not a singleton String s; } class bar { foo f; int i; } class baz { foo sameF; } Now we create instances foo onlyFoo = new foo("the only one"); bar theBar = new bar(onlyFoo, 123); baz theBaz = new baz(onlyFoo); After that we want to store them serilazed in a file. If we deserialze theBaz, modify onlyFoo and deserialize theBaz to the file again, theBar still contains the original onlyFoo, so there are two different versions of onlyFoo. What I want instead is that I store theBaz and theBar without onlyFoo, store the three objects separately and once

Why does Get-Date seem to return DateTime objects, but the BinarySerializer indicate it returns a PSObject?

不问归期 提交于 2019-12-01 18:22:14
Take the simple HashTable : $data = @{ First = 'Justin'; Last = 'Dearing'; StartDate = Get-Date '2002-03-23'; } The key StartDate seems to contain a DateTime . C:\Users\zippy\Documents> $data.StartDate.GetType().FullName System.DateTime However, if I attempt to perform binary serialization on it, I get an exception complaining that PSObject is not serializable. $ms = New-Object System.IO.MemoryStream $bf = New-Object System.Runtime.Serialization.Formatters.Binary.BinaryFormatter $bf.Serialize($ms, $data) $ms.Close() Throws: DocumentsException calling "Serialize" with "2" argument(s): "Type

Conditional C# Binary Serialization

允我心安 提交于 2019-12-01 13:05:19
I am using BinaryFormatter to serialize a class and its variables by condition. For example: [Serializable] public class Class1 { private Class2 B; ... } [Serializable] public class Class2{...} I want the variable B to be serialized only when remoting time, but not when i serialize it to file storage. Questions: 1) I know that in XmlSerialization we can use [XmlIgnore] and {PropertyName}Specified to ignore the property conditionally. Is that a equivalent method for [NonSerialized]? 2) For a class with [Serializable] attribute, how to ignore it at the runtime? There is no such method. You can

Conditional C# Binary Serialization

[亡魂溺海] 提交于 2019-12-01 11:18:43
问题 I am using BinaryFormatter to serialize a class and its variables by condition. For example: [Serializable] public class Class1 { private Class2 B; ... } [Serializable] public class Class2{...} I want the variable B to be serialized only when remoting time, but not when i serialize it to file storage. Questions: 1) I know that in XmlSerialization we can use [XmlIgnore] and {PropertyName}Specified to ignore the property conditionally. Is that a equivalent method for [NonSerialized]? 2) For a

binary serialization, adding a new field to class - will it work?

我的未来我决定 提交于 2019-12-01 05:03:22
问题 I have a client and a server application which communicate over .NET 2.0 Remoting using binary serialization. A small change has been made to one of the data transfer object's interface and the implementing class, well, an array of strings field was added. If I to redeploy a new version of server application, will my old clients continue to work? I would think they would, since nothing has been deleted from interface and direct implementation, but I am not sure. It probably boils down to