C
C#8mo ago
Kazibo

System.Text.Json: Modifying DerivedTypes list after initial resolution

Hello, I’m developing an app that has some components that are loaded later on in the application lifetime and I’m having an issue with serialising objects. I’m generating JsonSerializationOptions.PolymorphismOptions.DerivedTypes at runtime within a Modifier callback when a type is first serialised (and the JsonTypeInfo is first requested) and that’s all fine. But when I load a new assembly later on that contains another derived type of a type that has already had its JsonTypeInfo generated I can’t find a way to modify the DerivedTypes list to include the new type. It seems the JsonTypeInfos are cached globally/statically and all the mechanisms to regenerate them/invalid the cache are internal. I also can’t save the PolymorphismOptions object reference and modify it later because the object becomes read-only once it’s used for serialisation. Appreciate any thoughts folks might have. Many thanks
1 Reply
Kazibo
KaziboOP8mo ago
Never mind, the cache exists on the JsonSerializationOptions, which I was keeping as a global. Resetting that causes the type infos to be re-resolved. Thanks all!
Want results from more Discord servers?
Add your server