Роу Вілсон Фредеріск Холм
Warning about Trimmers and XmlSerializers
My library uses a trimmer to handle complex XML. But when I turned on code trimming for it, it showed warning
IL2026: [...] Members from serialized types may be trimmed if not referenced directly.
, the code looked like this:
I looked everywhere but didn't find any direct solutions, and the .NET XML serialization code seems to have been out of date for a long time, and lacks many features to circumvent reflection mechanisms, such as Source Generation, compared to JSON.
I don't want to overcomplicate the code, so my own guess at a solution is to create a new class and use the DynamicalAccessedMembersAttribute to prevent the trimmer from trimming key class fields and properties:
Is this correct? Are there any other possible correct options I have?3 replies