You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a type implements interface explicitly, then CA1859 gives false positive when th explicit implementation is used through the interface type.
#7558
Open
bharathkolanda opened this issue
Feb 3, 2025
· 1 comment
IFoo fooClone = new SampleHandler();
Change type of variable 'fooClone' from 'IFoo' to 'SampleHandler' for improved performance
bool attachResult = fooClone.Attach( workingContext );
Expected behavior
Actual behavior
CA1859 is raised for fooClone.Attach method, suggesting to change the type to SampleHandler.
The text was updated successfully, but these errors were encountered:
Analyzer
Diagnostic ID: CA1859:
Use concrete types when possible for improved performance
Analyzer source
SDK: Built-in CA analyzers in .NET 5 SDK or later
Version: SDK 8.0.101
Describe the bug
CA1859 is falsely raised when a type implements an interface explicitly. Applying the suggested fix leads to compilation errors.
Steps To Reproduce
interface IFoo
{
bool Attach(IContext context);
}
class SampleHandler : IFoo
{
bool IFoo.Attach(IContext context)
{
....
return true;
}
}
IFoo fooClone = new SampleHandler();
Change type of variable 'fooClone' from 'IFoo' to 'SampleHandler' for improved performance
bool attachResult = fooClone.Attach( workingContext );
Expected behavior
Actual behavior
CA1859 is raised for fooClone.Attach method, suggesting to change the type to SampleHandler.
The text was updated successfully, but these errors were encountered: