Kayıtlar

Aralık 24, 2014 tarihine ait yayınlar gösteriliyor

CA2202: Do not dispose objects multiple times hatasına yaklaşım

Visual studio.net ile projenizi açtınız. Ve solution explorer üzerinde sağ tuşa tıklayıp cod analyzer çalıştırdınız. Karşınıza başlıktaki gibi bir hata mesajı geliyorsa yapabileceğiniz çözüm try finally bloğunu kullanmaktır. Problemin kaynağı A method implementation contains code paths that could cause multiple calls to  IDisposable . Dispose  or a Dispose equivalent, such as a Close() method on some types, on the same object. Örneğin iç içe use kullandınız diyelim 1 2 3 4 5 6 7 using (Stream stream = new FileStream( "file.txt" , FileMode.OpenOrCreate)) { using (StreamWriter writer = new StreamWriter(stream)) { // Use the writer object... } } Daha sonra bu örneği değiştirmek istersek 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Stream stream = null ; try { stream = new FileStream( "file.txt" , FileMode.OpenOrCreate); using (StreamWriter writer = new StreamWriter(stream)) { stream = null ;