You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.
We were bit by a nasty issue that running CodeFormatter broke serialization of a type that had [DataMember] on a private field. CodeFormatter renamed the field, which caused the serialization format to change, so our pre-CodeFormatter and post-CodeFormatter serialization was incompatible.
Below program demonstrates the issue:
using System;
using System.Runtime.Serialization;
using System.Xml;
namespace DataMemberSample
{
class Program
{
static void Main(string[] args)
{
var myData = new MyData(5);
var dataContractSerializer = new DataContractSerializer(typeof(MyData));
using (var xw = XmlWriter.Create(Console.Out, new XmlWriterSettings { Indent = true }))
{
dataContractSerializer.WriteObject(xw, myData);
}
}
}
[DataContract]
class MyData
{
[DataMember]
private int MyInteger;
public MyData(int myInteger)
{
MyInteger = myInteger;
}
}
}
+1 on this. In MSBuild we use binary serialization all over (uhg) and changing private fields on [Serializable] classes changes the contract for serialization. It would be good to detect both of these and be able to disable renaming in those cases (even if it's an extra option).
Another irritant: renaming fields that are part of an interop struct and are intentionally named to match their C++ counterparts. Opened a separate issue for this:
We were bit by a nasty issue that running CodeFormatter broke serialization of a type that had [DataMember] on a private field. CodeFormatter renamed the field, which caused the serialization format to change, so our pre-CodeFormatter and post-CodeFormatter serialization was incompatible.
Below program demonstrates the issue:
Before CodeFormatter, produces the below output:
Running CodeFormatter renames
MyInteger
to_myInteger
, so now it produces this output:Of course we should have had tests that detected this issue, but I should feel confident that CodeFormatter will not affect code functionality.
The text was updated successfully, but these errors were encountered: