CA1869 'instance for every serialization operation' on 'JsonSerialzier' but not on 'BinaryData'

When using JsonSerializerOptions as a parameter to `JsonSerializer.Serialize(…)` and `JsonSerializer.Deserialize(…)`, passing JsonSerializerDefaults as a parameter suggests “Cache and reuse instances instead”

 

Meanwhile, `BinaryData.ToObjectFromJson(…)` that takes in the same parameter does not suggest that.

Should the same CA1969 be added to `BinaryData.ToObjectFromJson(…)` as well?

 

 

0
2 comments

I tried with the code snnipets you mentioned, when recreate the serializer options in BinaryData.ToObjectFromJson(), the CA1869 was not triggerred by it.

From the discription of CA1869: Cache and reuse 'JsonSerializerOptions' instances, the serializer in BinaryData namespace is not mentioned. Consider the BinaryData.ToObjectFromJson() is only provided in .NET 9 preview package, it could be an issue of Roslyn but not Rider. Both VS and Rider are showing the same result.

For the code quality rules provided by Roslyn, Rider will just reflect it “as-is”. You could create a new issue for Roslyn to see if it needs to be migrated for BinaryData as well.

0

I do not think I have .NET 9 installed on my computer, I'm working with .NET 8. Anyway, I understand that the rules received "as is" from Roslyn will not trigger that. I will try to dig a bit deeper when I have time. Thanks for the explanation.

1

Please sign in to leave a comment.