We use following method to serialize and encrypt an object which works fine
Rijndael rij = Rijndael.Create();
rij.Key = key;
rij.IV = iv;
using (CryptoStream cs = new CryptoStream(stream, rij.CreateEncryptor(), CryptoStreamMode.Write))
{
using (GZipStream zs = new GZipStream(cs, CompressionMode.Compress))
{
XmlSerializer xs = new XmlSerializer(typeof(T));
xs.Serialize(zs, obj);
zs.Flush();
zs.Close();
}
cs.Close();
}
But gives us reflectionpermission error when using following code in the medium trust. Works fine in full trust. Is there anything we could do to solve this problem in medium trust?
Rijndael rij = Rijndael.Create();
rij.Key = key;
rij.IV = iv;
T obj = default(T); // assigns null if T is a reference type, or 0 (zero) for value types
using (CryptoStream cs = new CryptoStream(stream, rij.CreateDecryptor(), CryptoStreamMode.Read))
{
using (GZipStream zs = new GZipStream(cs, CompressionMode.Decompress))
{
XmlSerializer xs = new XmlSerializer(typeof(T));
obj = (T)xs.Deserialize(zs);
zs.Close();
}
cs.Close();
}
bhav27
Member
79 Points
107 Posts
XmlSerializer error in medium trust
Jun 15, 2011 07:20 PM|LINK
Hi,
We use following method to serialize and encrypt an object which works fine
Rijndael rij = Rijndael.Create(); rij.Key = key; rij.IV = iv; using (CryptoStream cs = new CryptoStream(stream, rij.CreateEncryptor(), CryptoStreamMode.Write)) { using (GZipStream zs = new GZipStream(cs, CompressionMode.Compress)) { XmlSerializer xs = new XmlSerializer(typeof(T)); xs.Serialize(zs, obj); zs.Flush(); zs.Close(); } cs.Close(); }But gives us reflectionpermission error when using following code in the medium trust. Works fine in full trust. Is there anything we could do to solve this problem in medium trust?
Rijndael rij = Rijndael.Create(); rij.Key = key; rij.IV = iv; T obj = default(T); // assigns null if T is a reference type, or 0 (zero) for value types using (CryptoStream cs = new CryptoStream(stream, rij.CreateDecryptor(), CryptoStreamMode.Read)) { using (GZipStream zs = new GZipStream(cs, CompressionMode.Decompress)) { XmlSerializer xs = new XmlSerializer(typeof(T)); obj = (T)xs.Deserialize(zs); zs.Close(); } cs.Close(); }