views:

17

answers:

1

I was trying to write the following simple extension method for RSAKeyValue:

public static class RSAKeyValueExtensions
{
    public static string ToXmlString(this RSAKeyValue keyValue)
    {
        return keyValue.GetXml().OuterXml;
    }
}

However, it seems whenever I use ToXmlString, I get an exception:

System.ObjectDisposedException: Safe handle has been closed

Is there a way to encapsulate the GetXml().OuterXml so it isn't repeated in various places in my code without getting an ObjectDisposedException?

A: 

I don't think the problem is that I was using an extension method, I think I was getting that exception because I was calling GetXml() on the RSAKeyValue instance after the underlying RSACryptoServiceProvider had already been disposed.

Sarah Vessels