Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.

Commit c733aa8

Browse files
committed
#28 - Use a GZipStream constructor that's supported on Mono.
1 parent 8b0500d commit c733aa8

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/Microsoft.AspNet.Security/DataHandler/Serializer/TicketSerializer.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,25 @@ namespace Microsoft.AspNet.Security.DataHandler.Serializer
1313
{
1414
public class TicketSerializer : IDataSerializer<AuthenticationTicket>
1515
{
16+
private static readonly bool IsMono = Type.GetType("Mono.Runtime") != null;
1617
private const int FormatVersion = 2;
1718

1819
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2202:Do not dispose objects multiple times", Justification = "Dispose is idempotent")]
1920
public virtual byte[] Serialize(AuthenticationTicket model)
2021
{
2122
using (var memory = new MemoryStream())
2223
{
23-
using (var compression = new GZipStream(memory, CompressionLevel.Optimal))
24+
GZipStream compression;
25+
if (IsMono)
26+
{
27+
// The other constructor is not currently supported on Mono.
28+
compression = new GZipStream(memory, CompressionMode.Compress);
29+
}
30+
else
31+
{
32+
compression = new GZipStream(memory, CompressionLevel.Optimal);
33+
}
34+
using (compression)
2435
{
2536
using (var writer = new BinaryWriter(compression))
2637
{

0 commit comments

Comments
 (0)