In System.Xml.Serialization, XmlCustomFormater.cs the method GenerateToXmlStringCore does not correctly handle a null value for base64Binary and hexBinary. It returns String.Empty, but it should return null. In other words those two cases should look like this:
case "base64Binary": return value + " == null ? null : Convert.ToBase64String (" + value + ")";
case "hexBinary": return value + " == null ? null : ToBinHexString (" + value + ")";
Also, for the sake of consistency, the method ToXmlString should be fixed as well; however in this case the null checks are unnecessary since there is already a check before entering the switch statement.
Created attachment 1544 [details]
Proposed patch to XmlCustomFormatter.cs
I'm not sure why we need this. Does this differentiate the serialization results?
(No one is working on this namespace now so no one can guess what it is for.)
After creating and XML-serializing a new class with a null-able and not set property, output string will NOT contain this property TAG (it's correct behavior) and sometimes (NOT ALWAYS!, it's a function of time, hard to say who is blamable for this GC??? and when it can happen) it contains just closed tag <myproperty /> - this is not correct behavior. After such class de-serialization this property value will be equal to String.Empty (if property of type String) instead of NULL.
We have not received the requested information. If you are still experiencing this issue please provide all the requested information and reopen the bug report.