views:

87

answers:

1

I have read on MSDN(see Important note) that RSACryptoServiceProvider must be disposed. They give the example:

using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider())

Now I'm trying to include RSACryptoServiceProvider into MyClass making use of it in several Methods. With this setup I cannot use the using statement.

Instead I try to call the .Dispose() Method of the RSACryptoServiceProvider object at a suitable time but then I get the compile error message:

`System.Security.Cryptography.AsymmetricAlgorithm.Dispose(bool)' is inaccessible due to its protection level

Is RSACryptoServiceProvider not supposed to be used longer than one function call(using the using statement)?

How can I fix this, is not making the Dispose call an option?

A: 

The Clear method looks like it will call the dispose method:

This method is a simple call to the IDisposable.Dispose method. Calling Dispose allows the resources used by the AsymmetricAlgorithm class to be reallocated for other purposes. For more information about Dispose, see Cleaning Up Unmanaged Resources.

SwDevMan81
@phq: Alternatively, if for some reason you *insist* upon calling Dispose, then cast the value to IDisposable, and then call Dispose on the result of the cast. But better to do what the documentation says and call Clear.
Eric Lippert