Fix MA0139 false positive when the Serilog params array is passed as an array - #1607
Merged
Merged
Conversation
meziantou
marked this pull request as ready for review
September 23, 2026 04:35
This was referenced Sep 23, 2026
Bump Meziantou.Analyzer from 3.0.139 to 3.0.283
Analogy-LogViewer/Analogy.LogViewer.NLog.Targets#582
Closed
Closed
Bump Meziantou.Analyzer from 3.0.139 to 3.0.283
Analogy-LogViewer/Analogy.AspNetCore.LogProvider#563
Closed
Closed
Closed
Closed
Closed
Closed
Closed
This was referenced Oct 1, 2026
Closed
Open
Open
Bump Meziantou.Analyzer from 3.0.139 to 3.0.291
Analogy-LogViewer/Analogy.LogViewer.NLog.Targets#586
Open
Bump Meziantou.Analyzer from 3.0.139 to 3.0.291
Analogy-LogViewer/Analogy.AspNetCore.LogProvider#565
Open
Open
Open
Open
Open
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
For the Serilog methods (
Log.Information(string messageTemplate, params object?[]? propertyValues), ...), the values were read from the params array only when the call used the expanded form. When the array was passed directly (normal form), the call fell through to the fallback that uses each argument as a value, so the wholeobject[]was checked against the first placeholder:Fix
When the argument after the template is bound to the
paramsparameter, the values are the elements of the array creation, whether the call is in the expanded or in the normal form (implicit conversions are unwrapped). When the array is not created in the call (a variable, a method call,null...), its values are unknown, so no value is checked and only the placeholder names are validated, as when fewer values than placeholders are passed.The generic overloads (
Information<T>(string, T)) are unchanged: when they are selected, such as fornew string[] { "" }, the array is a single property value.Tests
Added
SeriLog_Log_Information_ParamsArrayInNormalForm(valid and invalid element innew object[] { ... }) andSeriLog_Log_Information_ParamsArrayVariable. Both failed before the fix.Ran the
LoggerParameterTypeAnalyzertests (MA0124 and MA0139) on roslyn5.9 and roslyn4.8 (63/63 passing on both).