开发者

ObjectDisposedException when using extension method on RSAKeyValue

开发者 https://www.devze.com 2023-01-06 10:10 出处:网络
I was trying to write the following simple extension method for RSAKeyValue: public static class RSAKeyValueExtensions

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 开发者_JAVA技巧repeated in various places in my code without getting an ObjectDisposedException?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消