runtime icon indicating copy to clipboard operation
runtime copied to clipboard

IPAddress isn't serializable on .net core

Open morde opened this issue 8 years ago • 8 comments

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.

morde avatar Jun 05 '18 12:06 morde

cc: @ViktorHofer @danmosemsft

davidsh avatar Jun 05 '18 14:06 davidsh

@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?

danmoseley avatar Jun 05 '18 15:06 danmoseley

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

ViktorHofer avatar Jun 05 '18 15:06 ViktorHofer

Seems like the question has been answered about why IPAddress is not marked serializable on .NET Core.

davidsh avatar Jun 13 '18 18:06 davidsh

@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?

Jasdo avatar Jul 24 '19 12:07 Jasdo

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?

danmoseley avatar Jul 24 '19 17:07 danmoseley

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?

Jasdo avatar Jul 24 '19 17:07 Jasdo

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.

ahsonkhan avatar Jul 25 '19 03:07 ahsonkhan