Questions tagged [ca2202]

Visual studio code analysis for managed code : Do not dispose objects multiple times. Use this tag when asking questions related to this warning.

This warning is caused when some code paths of a method might lead to attempting to dispose the same object more than once.

Official documentation states:

Cause
A method implementation contains code paths that could cause multiple calls to System.IDisposable.Dispose or a Dispose equivalent, such as a Close() method on some types, on the same object.

Rule description
A correctly implemented Dispose method can be called multiple times without throwing an exception. However, this is not guaranteed and to avoid generating a System.ObjectDisposedException you should not call Dispose more than one time on an object.

17 questions
0
votes
2 answers

CA2000/CA2202 for Stream in a using statement

CA2000 and CA2202 warnings have recently been the bane of my existence. What am I doing wrong here? I basically get a FileStream using File.Open and then pass it into a function that may return a new stream or may return the same stream. I then…
sohum
  • 3,207
  • 2
  • 39
  • 63
-1
votes
1 answer

You should not call Dispose more than one time on an object (CA2202)

I've seen posts on this question but I can't seem to get rid of the warning by following the examples here and other places online. Do you see what I am missing to avoid getting the CA2202 Warning that says: To avoid generating a…
Rich
  • 6,470
  • 15
  • 32
  • 53
1
2