diff --git a/src/NetAnalyzers/Core/Microsoft.CodeQuality.Analyzers/ApiDesignGuidelines/UriParametersShouldNotBeStrings.cs b/src/NetAnalyzers/Core/Microsoft.CodeQuality.Analyzers/ApiDesignGuidelines/UriParametersShouldNotBeStrings.cs index 9d66b410eb..0690635dd7 100644 --- a/src/NetAnalyzers/Core/Microsoft.CodeQuality.Analyzers/ApiDesignGuidelines/UriParametersShouldNotBeStrings.cs +++ b/src/NetAnalyzers/Core/Microsoft.CodeQuality.Analyzers/ApiDesignGuidelines/UriParametersShouldNotBeStrings.cs @@ -104,6 +104,12 @@ public void Analyze(SymbolAnalysisContext context) return; } + if (method.IsImplementationOfAnyInterfaceMember()) + { + // should not warn for implementations of interfaces that may be out of our control + return; + } + if (context.Options.IsConfiguredToSkipAnalysis(Rule, method, context.Compilation)) { // property is excluded from analysis diff --git a/src/NetAnalyzers/UnitTests/Microsoft.CodeQuality.Analyzers/ApiDesignGuidelines/UriParametersShouldNotBeStringsTests.cs b/src/NetAnalyzers/UnitTests/Microsoft.CodeQuality.Analyzers/ApiDesignGuidelines/UriParametersShouldNotBeStringsTests.cs index 9c00f279d0..6600b179b7 100644 --- a/src/NetAnalyzers/UnitTests/Microsoft.CodeQuality.Analyzers/ApiDesignGuidelines/UriParametersShouldNotBeStringsTests.cs +++ b/src/NetAnalyzers/UnitTests/Microsoft.CodeQuality.Analyzers/ApiDesignGuidelines/UriParametersShouldNotBeStringsTests.cs @@ -153,6 +153,36 @@ public static void Method(Uri url, Uri url2) { } } + [Fact, WorkItem(6371, "https://github.com/dotnet/roslyn-analyzers/issues/6371")] + public async Task CA1054NoWarningsForInterfaceImplementationsAsync() + { + await VerifyCS.VerifyAnalyzerAsync(@" + using System; + + public interface IUrlInterface1 + { + void Method(string url); + } + + public interface IUrlInterface2 + { + void Method(string url); + } + + public class A : IUrlInterface1, IUrlInterface2 + { + public void Method(string url) // Implements IUrlInterface1, implicitly + { + } + + void IUrlInterface2.Method(string url) // Implements IUrlInterface2, explicitly + { + } + } +", GetCA1054CSharpResultAt(6, 28, "url", "IUrlInterface1.Method(string)") + , GetCA1054CSharpResultAt(11, 28, "url", "IUrlInterface2.Method(string)")); + } + [Fact] public async Task CA1054NoWarningNotPublicAsync() {