c# - CA2000 : Microsoft.Reliability : Call System.IDisposable.Dispose on object 'dt' before all references to it are out of scope -
i need advice.when run code analysis tool following
warning 1 ca2000 : microsoft.reliability : in method 'class1.test.testmethod()', object 'dt' not disposed along exception paths. call system.idisposable.dispose on object 'dt' before references out of scope. how resolve warnings??
public void testmethod() { datatable dt = new datatable(); datatable dt1= new datatable(); try { if (dt.rows.count == 0) { dt1.merge(dt); } } catch { throw; } { if (dt != null) dt.dispose(); if (dt1 != null) dt1.dispose(); } }
not sure why getting error, can try using statement block in method , see if error goes away. try like:
public void testmethod() { using (datatable dt = new datatable()) using (dataview dv = new dataview(dt)) { //your work } }
Comments
Post a Comment