It seems that the OptionalFieldAttribute is not longer (if ever) needed for serialization with BinaryFormatter.
With a example from codeguru there is no longer any exception thrown when building the code in Visual Studio 2010, even when targeting older versions of the .NET framework.
Another question on stackoverflow suggests that it's always been optional. Is this true? And if so, is there actually not any way to get a exception for a missing field, when serializing to binary content in .NET?
To get the exception, add this statement to the deserialization code:
formatter.AssemblyFormat = FormatterAssemblyStyle.Full;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With