IPAddress isn't serializable on .net core
IPAddress isn't mark serializable on .net core, although, it does on .net framework. As far as I can see, there is nothing that can cause that change.
cc: @ViktorHofer @danmosemsft
@morde we are more selective with the types we made serializable in.NET Core because of the maintainability and security pitfalls it can bring. Can you share why you need it to be serializable with the binary formatter?
Marking types as serializable has several drawbacks, i.e. exposing internals like a type's data structure which makes modernizing these types very hard. For more info see https://github.com/dotnet/corefx/issues/19119
Seems like the question has been answered about why IPAddress is not marked serializable on .NET Core.
@danmosemsft What if you have a distributed system, and you need to pass the type between machines (for example, using grpc). Any suggestion how can it be done?
This isn't my area, but I believe in general serialization mechanisms have built in knowledge of some basic types like common collections, and require help to serialize others either by annotation (not applicable here) or some kind of converter. Binary formatter (which is what is discussed above) was a bit special because it used private implementation details of the types, which was part of what made it fragile and sometimes dangerous. That's not an approach we want to take forward.
For example for our JSON serializer, it understands built in types and common collections, and for others you pass in JsonConverter objects that know how to translate to and from. In future, it could be educated about other commonly serialized types for which the convertesr would become unnecessary. @ahsonkhan is this a reasonable characterization? @JamesNK what is the usual recommended approach for de/serializing .NET objects to go over gRPC?
Thank you for the quick response. Actually I'm interested in an answer for the last question - What is the usual recommended approach for de/serializing .NET objects to go over gRPC?
For example for our JSON serializer, it understands built in types and common collections, and for others you pass in JsonConverter objects that know how to translate to and from. In future, it could be educated about other commonly serialized types for which the convertesr would become unnecessary. @ahsonkhan is this a reasonable characterization?
Yep, that's correct. In the case of IPAddress, you would need to hook in your custom converter since it is not supported out-of-the-box within the JSON serializer.