Diagnostic ID: CA2200: Rethrow to preserve stack details
SDK: Built-in CA analyzers in .NET 5 SDK or later
Version: SDK 5.0.100-preview.8
The caught exception ex is only thrown when it is mapped into a different exception by the MapSendException(...) method. The analyzer should not warn in this case, further I would assume CA2200 should not warn when the catch block is throwing a different exception (mappedEx) than the catched exception (ex)
try
{
...
}
catch (Exception ex) when (MapSendException(ex, cancellationToken, out Exception mappedEx))
{
throw mappedEx;
}
The exact warning found here, related to https://github.com/dotnet/runtime/pull/42957#discussion_r498532030
Should not warn in above case
Warning
A similar case is being tested:
@Evangelink Was this fixed in your re-write of the analyzer? or it should have been working from before the rewrite?
@buyaa-n Can you test with the latest package from https://dev.azure.com/dnceng/public/_packaging?_a=package&feed=dotnet6&package=Microsoft.CodeAnalysis.NetAnalyzers&protocolType=NuGet&version=6.0.0-preview1.20501.5&view=overview? I suspect @Evangelink's recent fix in master would have fixed this. We should consider backporting the change to release/dotnet5-rc2 branch if that is the case.
A similar case is being tested:
@Evangelink Was this fixed in your re-write of the analyzer?
Yep, it is the same case, looks already fixed
@buyaa-n Can you test with the latest package from https://dev.azure.com/dnceng/public/_packaging?_a=package&feed=dotnet6&package=Microsoft.CodeAnalysis.NetAnalyzers&protocolType=NuGet&version=6.0.0-preview1.20501.5&view=overview? I suspect @Evangelink's recent fix in master would have fixed this. We should consider backporting the change to release/dotnet5-rc2 branch if that is the case.
Yep i used RC2 branch, not master, agree we should port it to RC2
@buyaa-n Can you test with the latest package from https://dev.azure.com/dnceng/public/_packaging?_a=package&feed=dotnet6&package=Microsoft.CodeAnalysis.NetAnalyzers&protocolType=NuGet&version=6.0.0-preview1.20501.5&view=overview
Hm, i still see the warning with that version
@buyaa-n Interesting! Let me add a test and debug it.
I didn't consider this case, honestly that's the first time I am seeing this pattern :)
@Youssef1313 has already filed a PR