Skip to content

Fix MA0184 false positive on empty interpolated strings with custom handlers#1001

Merged
meziantou merged 2 commits intomainfrom
copilot/fix-empty-string-error
Feb 10, 2026
Merged

Fix MA0184 false positive on empty interpolated strings with custom handlers#1001
meziantou merged 2 commits intomainfrom
copilot/fix-empty-string-error

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 10, 2026

MA0184 incorrectly flagged $"" when passed to methods accepting only custom interpolated string handlers (no string overload).

public static void MyAPI([InterpolatedStringHandlerArgument] ref MyHandler handler) { }

MyAPI($"something");  // Correctly not flagged
MyAPI($"");           // False positive - now fixed

Root Cause

Empty interpolated strings generate no IInterpolatedStringAppendOperation parts in Roslyn's operation tree. The analyzer only checked the immediate parent operation, missing the parameter type context nested further up the tree.

Changes

  • Walk entire parent operation chain instead of checking only immediate parent
  • Detects custom handlers via conversions, method argument parameters, and variable assignments at any level
  • Added test coverage for empty string case

All 13 existing tests pass.

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/tests/Meziantou.Analyzer.Test/Meziantou.Analyzer.Test.csproj --packages /home/REDACTED/work/Meziantou.Analyzer/.codeql-scratch/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/home/REDACTED/work/Meziantou.Analyzer/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/home/REDACTED/work/Meziantou.Analyzer/.codeql-scratch/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 /home/REDACTED/work/Meziantou.Analyzer/.codeql-scratch/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/home/REDACTED/work/Meziantou.Analyzer/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/home/REDACTED/work/Meziantou.Analyzer/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot /p:AllowMissingPrunePackageData=true (dns block)
    • Triggering command: /usr/share/dotnet/dotnet dotnet restore --no-dependencies /home/REDACTED/work/Meziantou.Analyzer/Meziantou.Analyzer/tests/Meziantou.Analyzer.Test/Meziantou.Analyzer.Test.csproj --packages /home/REDACTED/work/Meziantou.Analyzer/.codeql-scratch/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/home/REDACTED/work/Meziantou.Analyzer/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/home/REDACTED/work/Meziantou.Analyzer/.codeql-scratch/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/tests/Meziantou.Analyzer.Test/Meziantou.Analyzer.Test.csproj --packages /home/REDACTED/work/Meziantou.Analyzer/.codeql-scratch/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/home/REDACTED/work/Meziantou.Analyzer/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/home/REDACTED/work/Meziantou.Analyzer/.codeql-scratch/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:

Original prompt

This section details on the original issue you should resolve

<issue_title>[MA0184] False positive on empty string</issue_title>
<issue_description>### Version of the Meziantou.Analyzer NuGet package

2.0.298

Rule Identifier

MA0184

Target Framework

net10.0

C# Language version

C# 14

Description

I have an API, that accepts only interpolation handler (no string-based overloads).

public static void MyAPI([InterpolatedStringHandlerArgument] ref MyInterpolatedStringHandler handler)
{
}

There are few cases where I need to pass plain string to it which I do using MyAPI($"something") and it doesn't trigger MA0184 as expected. But for MyAPI($"") call I'm getting analyzer error.

Reproduction Steps

Minimal code:

code to reproduce the error

Other information

No response</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…ring handlers

Co-authored-by: meziantou <509220+meziantou@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix false positive on empty string for MA0184 Fix MA0184 false positive on empty interpolated strings with custom handlers Feb 10, 2026
Copilot AI requested a review from meziantou February 10, 2026 15:37
@meziantou meziantou marked this pull request as ready for review February 10, 2026 15:51
@meziantou meziantou merged commit c7ab008 into main Feb 10, 2026
13 checks passed
@meziantou meziantou deleted the copilot/fix-empty-string-error branch February 10, 2026 17:44
This was referenced Feb 10, 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.

[MA0184] False positive on empty string

2 participants