I'm getting string result from web service and parsing it with the following code:
public static T FromXmlString<T>(string xml)
{
T xmlClass = default(T);
using (TextReader reader = new StringReader(xml))
{
try
{
xmlClass =
(T)new XmlSerializer(typeof(T)).Deserialize(reader);
}
catch (InvalidOperationException e)
{
//
}
}
return xmlClass;
}
In the result there is compressed string , after parsing I try to decompress it with the following code
byte[] bytes = Convert.FromBase64String(voucher.Document.Value);
using (var compressedStream = new MemoryStream(bytes))
using (var zipStream = new GZipStream(compressedStream, CompressionMode.Decompress))
using (var resultStream = new MemoryStream())
{
zipStream.CopyTo(resultStream);
return File(resultStream.ToArray(), "application/pdf", "voucher.pdf");
}
But I fail every time. It throws the below error: "The magic number in GZip header is not correct. Make sure you are passing in a GZip stream."
I know there are a lot of questions similar to this. I tried every answers in the following links:
Compression/Decompression string with C#
Error decompressing gzipstream -- The magic number in GZip header is not correct
But did not get any result. So guys, do you have any idea why do I get this error. What is wrong with my code?
Thanks in advance!