2

I have a DataSet that I would like to cache in the ASP.NET's web cache. The content does not change very often and a cache of a few hours should work.

My problem is that when I create the DataSet, I get a CA2000 warning about dispose needing to be called. However, some articles say that I can cache the DataSet. I don't believe the DataSet directly implements Dispose; however, it is derived from a class that does.

What is the best way to cache a DataSet so I do not receive the CA2000 warning?

Peter Rilling
  • 323
  • 3
  • 7
  • Indeed, you don't need to dispose a DataSet in the general case. Post your code. – Icarus Aug 01 '13 at 18:51
  • I would really like to see an answer to this; I have some legacy code which has a DAL based on Enterprise Library that slings DataSets around like they are going out of fashion; these DataSets work their way back up to the UI (an ASP.NET application) which does not explicitly dispose them. When I run Code Analysis on the DAL looking for undisposed connection objects, data readers etc, I get literally hundreds of these almost-false-positives from the undisposed datasets. – David Keaveny Jul 28 '15 at 01:29

1 Answers1

1

I do not get the same warning you are getting; but indeed, you don't need to dispose a DataSet in the general case as it doesn't contain any unmanaged resources.

See this other answer.

Community
  • 1
  • 1
Icarus
  • 63,293
  • 14
  • 100
  • 115