serialization

JSON: Serializing types derived from IEnumerable

JavaScriptSerializer serializes types derived from IEnumerable as JavaScript arrays. It convenient for arrays and lists but in some cases I need to serialize properties declared in derived type (e.g. Key in IGrouping). Here some sample code: var items = new[] { "aaabbb", "abcd", "bdsasd", "bsdqw" }; IGrouping<char, string> data = items....

Using System.Web.Script.Serialization.JavascriptSerializer to deserialize JSON - how to?

Note: I posted a similar question, which was the ancestor of this question, as I was originally thinking of using JSON.NET to parse the JSON, but I'm using the built-in deserializer, so it's a different question. This is what I'm trying to do: I have a class called Item, for example. The json has many "elements" (if that's what they are...

What's your data serialisation format of choice?

I'm interested to see who favours more obscure data serialisation formats over the more obvious ones (JSON, XML and Yaml). What do you tend to use? What syntax do you prefer? ...

Are BinaryFormatter Serialize and Deserialize thread safe?

Referencing this answer to a question. Can this be rewritten as: private static BinaryFormatter formatter = new BinaryFormatter(); public static T DeepClone<T>(this T a) { using(MemoryStream stream = new MemoryStream()) { formatter.Serialize(stream, a); stream.Position = 0; return (T)formatter.Deserialize(stream)...

Multiple Interface Inheritence without using Interfaces

Yes, the title doesn't make much sense, but here's my situation. I have two interfaces, say IGen and ITrans. Some of my classes implement IGen, some implement ITrans and some implement both ITrans has one method (Translate) and IGen has one method (Generate). For the classes that implement both ITrans and IGen Generate simply calls Tra...

does linq-to-sql entity serialization work out of the box?

If I try to serialize a linq-to-sql entity, will it by default serialize only the primitive fields or will it try to access the relationship fields as well? If it tries to grab relationship fields, is there a way to override this? ...

OnSerializingAttribute vs ISerializable

I was reading custom serialization article on msdn: http://msdn.microsoft.com/en-us/library/ty01x675%28VS.80%29.aspx It mentions that there are two ways of implementing custom serialization: 1, using OnDeserializedAttribute, OnDeserializingAttribute, OnSerializedAttribute, OnSerializingAttribute 2, implement ISerializable interface Ac...

C# Serializing a Collection of Objects

I am working on a ASP.NET application that has a class that inherits a List of a Custom Object. public class UserRoleList : List<UserRoleBO> { public UserRoleList() { } } How do I make this class serializable in C#? ...

C# Deserialize a class which has moved or been renamed

If I have a class named "MyClass" in an assembly named "AssemblyA" and serialize it to a file using .NET's BinaryFormatter. Then move the code of "MyClass" into an assembly named "AssemblyB" and try to deserialize the file I get the following "System.TypeLoadException" exception: Could not load type 'AssemblyA.MyClass' from assembly ...

XML Serialize Friend Classes in VB.net

I have a few classes (about 15 or so) in VB.net (2005) that I would like to be able to serialize to xml. Unfortunately they are labeled as friend classes and cannot be exposed outside of the assembly. The assembly is a dll that is a com interop plugin to a CAD system. I have set all of my classes as friends so that they are not exposed ...

Java serialization of multidimensional array

Hey everyone, Is it possible to make a 2D array in java serializable? If not, i am looking to "translate" a 3x3 2D array into a Vector of Vectors. I have been playing around with vectors, and I am still unsure of how to represent that. Can anyone help me? Thanks! ...

Circular reference exception when serializing LINQ to SQL classes

I have a set of linq to sql classes and serialized them into JSON using the .NET JavaScriptSerializer. However, as soon as I add record onto a relating table, serialization throws a "Circular reference exception". Aaarggh! It's described in detail here. I have a few options Convert the linq to sql class to a class with no relationsh...

Web Services in C# .NET and objects serialization - basic questions.

Hello folks. I am trying to create a simple web service in .NET but my knowledge is limited on that subject. Here is the code of this web service: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Services; namespace WebService1 { /// <summary> /// Summary description for Se...

XmlAttribute/XmlElement equivalent for JavaScriptSerializer

Is there an equivalent Attribute that can be placed on object Properties in a .NET Class that would perform the equivalent of XmlElement or XmlAttribute? [XmlRoot("objects")] public class MyObjects: List<MyObject> { } [XmlRoot("object")] public class MyObject { [XmlAttribute("name")] public string Name { get; set; } [XmlAttribute...

Is the Hessian class SerializerFactory thread-safe?

I'd like to use the Hessian (Java) serialization and need to create a SerializerFactory with custom serializers (to handle BigInteger). Can I create one of these and share it among threads? ...

Problem deserializing generic List's with C# XmlSerializer

Hello, I've come up against a bit of a brick wall with Microsoft's .net XmlSerializer. I'm trying to deserialize some XML into an object, which is fine if I'm using a single object, but the problem comes when one puts an object into a List and tries to serialize/deserialize that. First up, here's a sample C# windows console program to...

Unable to generate a temporary class (result=1). CS0266

I am getting this error only on one test server but the code works on other servers as well as my dev machine. Unable to generate a temporary class (result=1). error CS0266: Cannot implicitly convert type 'xxx.xxx.xxx.xxx.MessageHeaderMessageId?' to 'xxx.xxx.xxx.xxx.MessageHeaderxxxCode?'. An explicit conversion exists (are yo...

A type of generic list deserialization class?

OK, so here's the story so far. I could already deserialize individual objects using XmlSerializer, but deserializing lists was proving to be a real headache. I started out by trying to serialize List<Foo> and the serializer serialized multiple <Foo> XML structures inside a root <ArrayOfFoo> element. That proved to be problematic to d...

How to serialize objects in flex for a c# backend

We are developing an app with a Flex frontend and a C# backend, connected through web services. We are using the FLex Builder 3's Web Service Manager to autogenerate the webservice classes. The problem araise when Flex serialize our objects, for example, when we have a Number property with no value, this is serialized as NaN, and our bac...

Java Serializable, ObjectInputstream, Non-blocking I/O

I'm just starting out with Java serialization, and I'm not clear on how you are supposed to get objects from a source in a scenario with non-blocking I/O . All the documentation I can find suggests using ObjectInputStream is the proper way to read in serialized objects. However, as I mentioned I'm using java.nio and performing non-block...