Click here to Skip to main content
14,830,889 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to use the following code to dispose the objects..

protected void Dispose( bool disposing )
if( disposing )
{ if(components != null)
{ components.Dispose(); }
base.Dispose( disposing ); }

but i am getting the error

'object' does not contain a definition for 'Dispose'
tumbledDown2earth 12-Apr-13 2:34am
which line in your code above gives this error?
tumbledDown2earth 12-Apr-13 2:36am
if its this line
---- base.Dispose( disposing ); }

then you must have not derived your class from any user defined class.
thus default base class "object" .. which does not implement IDisposable()

Replace the line
base.Dispose( disposing );

IDisposable disposable = base as IDisposable;
if (disposable != null)

In case that your base class does not implement IDisposable, the disposable object will be null - do not call Dispose here.
And the method in your class should be public or public virtual or public override, not only protected.
Abhinav S 12-Apr-13 5:58am
You are using protected in Dispose. Thus you need to ensure object inherits a Disposable object.
This is normally done by implementing an IDisposable interface.

Implementing IDisposable and the Dispose Pattern Properly[^] should help you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900