c# - Why do I get a "Do not dispose objects multiple times" warning on a single using clause? -



c# - Why do I get a "Do not dispose objects multiple times" warning on a single using clause? -

this question has reply here:

ca2202: not dispose objects multiple times 1 reply

i have next code (as example):

using(stream s = new filestream(path)) using(gzipstream gz = new gzipstream(s, compressionmode.compress)) { //do stuff here }

i getting ca2202 "do not dispose objects multiple times" error here. because don't utilize leaveopen parameter in gzipstream?

i have gotten similar errors elsewhere single using statement, apparently multiple calls dispose().

is same problem this question, or else?

because gzipstream disposes of stream. prepare either utilize leaveopen parameter on constructor (which doesn't create much sense in case since want closed anyway) or combine statements:

using(var gz = new gzipstream(new filestream(path), compressionmode.compress)) { // stuff here }

c# code-analysis dispose

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -