Skip to content

Fix MA0135/MA0139: Serilog @ destructuring prefix not stripped consistently for multi-parameter log calls#1089

Merged
meziantou merged 2 commits intomainfrom
copilot/fix-ma0135-serilog-glitches
Apr 8, 2026
Merged

Fix MA0135/MA0139: Serilog @ destructuring prefix not stripped consistently for multi-parameter log calls#1089
meziantou merged 2 commits intomainfrom
copilot/fix-ma0135-serilog-glitches

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 8, 2026

MA0135/MA0139 inconsistently stripped the Serilog @ destructuring prefix depending on the number of log arguments. With a single argument, {@foo} was correctly resolved to foo in LoggerParameterTypes.txt. With multiple arguments, stripping was skipped, requiring @foo in the config instead — contradicting the single-argument behavior.

// Single param: analyzer strips @, expects "foo" in config ✓
logger.Debug("{@foo}", new object());

// Multiple params: analyzer did NOT strip @, expected "@foo" in config ✗
logger.Debug("{@foo}, {@tar}", new object(), new object());

// Mixed: also did NOT strip @, expected "@foo" ✗
logger.Debug("{bar}, {@foo}", 123, new object());

Root cause: potentialNamePrefixes = SerilogPrefixes was set inside the if (arguments.Length == templateIndex + 2) guard, which only matches when there is exactly one argument after the message template (the params-array overload case). Typed generic overloads with 2+ arguments bypassed it entirely.

Fix: Move potentialNamePrefixes = SerilogPrefixes unconditionally into the Serilog branch, outside the single-argument guard. The @/$ prefix is now always stripped for Serilog log method calls regardless of argument count. LoggerParameterTypes.txt entries should always be written without the @ prefix (e.g. foo;System.Object, not @foo;System.Object).

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 1s1vsblobprodcus386.vsblob.vsassets.io
    • Triggering command: /usr/share/dotnet/dotnet dotnet restore --no-dependencies /home/REDACTED/work/Meziantou.Analyzer/Meziantou.Analyzer/Meziantou.Analyzer.slnx --packages /tmp/codeql-scratch-8ad8dc5536a632e8/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/tmp/codeql-scratch-8ad8dc5536a632e8/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/tmp/codeql-scratch-8ad8dc5536a632e8/dbs/csharp/working/emptyFakeDotnetRoot /p:AllowMissingPrunePackageData=true (dns block)
  • pdfvsblobprodcus380.vsblob.vsassets.io
    • Triggering command: /usr/share/dotnet/dotnet dotnet restore --no-dependencies /home/REDACTED/work/Meziantou.Analyzer/Meziantou.Analyzer/Meziantou.Analyzer.slnx --packages /tmp/codeql-scratch-8ad8dc5536a632e8/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/tmp/codeql-scratch-8ad8dc5536a632e8/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/tmp/codeql-scratch-8ad8dc5536a632e8/dbs/csharp/working/emptyFakeDotnetRoot /p:AllowMissingPrunePackageData=true (dns block)
  • st8vsblobprodcus339.vsblob.vsassets.io
    • Triggering command: /usr/share/dotnet/dotnet dotnet restore --no-dependencies /home/REDACTED/work/Meziantou.Analyzer/Meziantou.Analyzer/Meziantou.Analyzer.slnx --packages /tmp/codeql-scratch-8ad8dc5536a632e8/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/tmp/codeql-scratch-8ad8dc5536a632e8/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/tmp/codeql-scratch-8ad8dc5536a632e8/dbs/csharp/working/emptyFakeDotnetRoot /p:AllowMissingPrunePackageData=true (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

… of parameters

Agent-Logs-Url: https://github.com/meziantou/Meziantou.Analyzer/sessions/302b5114-08cd-481e-88f9-918228065114

Co-authored-by: meziantou <509220+meziantou@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix MA0135 glitches with Serilog ILogger Fix MA0135/MA0139: Serilog @ destructuring prefix not stripped consistently for multi-parameter log calls Apr 8, 2026
Copilot AI requested a review from meziantou April 8, 2026 01:25
@meziantou meziantou marked this pull request as ready for review April 8, 2026 01:33
@meziantou meziantou enabled auto-merge (squash) April 8, 2026 01:35
@meziantou meziantou merged commit 1db805c into main Apr 8, 2026
13 checks passed
@meziantou meziantou deleted the copilot/fix-ma0135-serilog-glitches branch April 8, 2026 01:38
This was referenced Apr 8, 2026
This was referenced Apr 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MA0135 glitches with Serilog.ILogger depending on the number of log parameters and destructuring characters(@)

2 participants