-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Add an analyzer that warns on single-use JsonSerializerOptions instances #65396
Copy link
Copy link
Closed
dotnet/roslyn-analyzers
#6850Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedapi-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-System.Text.Jsonblocking-releasecode-analyzerMarks an issue that suggests a Roslyn analyzerMarks an issue that suggests a Roslyn analyzerin-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is mergedtenet-performancePerformance related issuePerformance related issue
Milestone
Metadata
Metadata
Assignees
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedapi-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-System.Text.Jsonblocking-releasecode-analyzerMarks an issue that suggests a Roslyn analyzerMarks an issue that suggests a Roslyn analyzerin-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is mergedtenet-performancePerformance related issuePerformance related issue
Type
Fields
Give feedbackNo fields configured for issues without a type.
Forked from #40072.
While #64646 mitigates most of the performance issues related to creating single-use
JsonSerializerOptionsinstances, this is still a suboptimal pattern and users are better off working with singletonJsonSerializerOptionsinstances. We should add an analyzer that warns about any JsonSerializerOptions construction that flows only to a call to a JsonSerializer method argument.The analyzer should warn if any of the following patterns are detected:
or if we're passing a local that has been initialized in the same method
In both cases the analyzer should recommend lifting the options instance to a static variable or use DI, but would most likely not provide a fixer.