Core.System.Configuration.Install
Core.System.Configuration.Install copied to clipboard
Evaluate replacing JsonConvert serialization
It looks like you're just using JSON.net to serialize IDictionary in savedState and this could be accomplished with built-in serializers that would remove the dependency on JSON.net (so that a different version can be used or just not bring that dependency along with someone using System.Configuration.Install).
I looked at the reference source and the built-in classes use NetDataContractSerializer which can serialize/deserialize arbitrary types in an IDictionary. We don't have that in netstandard2.0. Another possibility is BinaryFormatter, but that requires ISerializable which IDictionary is not. The concrete type is Hashtable in the underlying implementation for installers.
@flamencist thought this approach might work, but it relies on ToString() to put it in a key value store. Since IDictionary (and Hashtable) can hold any object, this doesn't really work. Some objects may not have a sensible ToString() which would end up with the type name in the output, and they can't really be deserialized in this manner.
In the Installer source I looked at, it appeared that it was putting an integer in there for the count of Installers and then saving all the child Installer states (which can be any object since anyone can inherit Installer).
The reason JsonConvert works is that it serializes the type information too. Is it possible to replace it with something we have in netstandard2.0 so that we don't have to bring along a JSON.Net dependency?
@flamencist Instead of using DataContractSerializer, have you thought about just using System.Text.Json? The library can be multi-targeted to netstandard2.0 using the NuGet package and netcoreapp3.0 for Core 3.0+ built-in support? It's pretty simple since you're the serializer and deserializer.
Do you want a simple PR for that vs the changes that were started 1.5 years ago to make it a new class in your feature branch?
Yes it's good to use System.Text.Json I'll appreciate if you help with json serialization
I just looked into it some more. System.Text.Json does not allow deserializing arbitrary unknown types based on type information like NetDataContractSerializer and Newtonsoft.Json. I don't see a way to do it without one of those, and we don't have NetDataContractSerializer in Core.
It's not safe to allow type information to come in with the content to deserialize and that's why they've deprecated things like that, I believe. However, for backward compatibility, it's needed here since it's serializing IDictionarys filled with data of unknown types by consumers you don't control. I don't see a way to do this without letting the type data being serialized to the file.
It looks like that's why your tests of DataContractSerializer failed too in your feature branch: it doesn't serialize the type information so it can't be round-tripped.
I guess this issue might need to be closed and keep the Newtonsoft dependency?