I finally stumbled on the reasons (two separate cases) for the false positives even when the pattern recommended in the MSDN documentation here for CA2000 Dispose Objects Before Losing Scope is followed:
If the name of the temporary disposable variable is not of the exact pattern shown, that is the string "temp" prepended in camelCase to the destination disposable, a false positive will be generated from a failure to recognize the recommended pattern. The false positive is easily eliminated with a name change.
If the destination disposable variable is a property instead of a field or local, the pattern is not recognized. Eliminating the false positive here requires writing a single-use function like so:
void SomeMethod() { // : HexgridPath = SetGraphicsPath(); // : } GraphicsPath SetGraphicsPath() { GraphicsPath path = null; GraphicsPath tempPath = null; try { tempPath = new GraphicsPath(); tempPath.AddLines(new Point[] { new Point(GridSize.Width*1/3, 0), new Point(GridSize.Width*3/3, 0), new Point(GridSize.Width*4/3,GridSize.Height/2), new Point(GridSize.Width*3/3,GridSize.Height ), new Point(GridSize.Width*1/3,GridSize.Height ), new Point( 0,GridSize.Height/2), new Point(GridSize.Width*1/3, 0) } ); path = tempPath; tempPath = null; } finally { if(tempPath!=null) tempPath.Dispose(); } return path; }
The first situation looks like a typical "junior-programmer's-first-assignment-just-out-of-school" error;
The second case is probably harder to fix, but is annoying.
Hopefully others who encounter these false positives can benefit from this analysis. In the long run small code changes are better than simply disabling the error, in case a junior programmer down the line "optimizes" the remedy out.