有人能告诉我如何从下面的代码中删除所有CA2202警告吗?
public static byte[] Encrypt(string data, byte[] key, byte[] iv)
{
using(MemoryStream memoryStream = new MemoryStream())
{
using (DESCryptoServiceProvider cryptograph = new DESCryptoServiceProvider())
{
using (CryptoStream cryptoStream = new CryptoStream(memoryStream, cryptograph.CreateEncryptor(key, iv), CryptoStreamMode.Write))
{
using(StreamWriter streamWriter = new StreamWriter(cryptoStream))
{
streamWriter.Write(data);
}
}
}
return memoryStream.ToArray();
}
}
警告7 CA2202:Microsoft.Usage:对象""CryptoStream""可以在方法""CryptoServices.Encrypt(string,byte[],byte[])""中释放多次."若要避免生成System.ObjectDisposedException,不应对一个对象多次调用Dispose.语法:LINES:34
警告8 CA2202:Microsoft.用法:对象"memoryStream"可以在方法"CryptoServices"中多次释放.加密(字符串,字节[],字节[]).避免生成系统.ObjectDisposedException您不应该对一个对象多次调用Dispose:线路:34、37
您需要Visual Studio代码分析才能看到这些警告(这些不是C#编译器警告).