Skip to content

Commit

Permalink
feat: support .NET 8.0 | Remove BinaryFormatter from `TestingExcept…
Browse files Browse the repository at this point in the history
…ion` (#383)

- #381 

Remove `BinaryFormatter` and serialization support for
`TestingException` as the [`BinaryFormatter` becomes
obsolete](https://github.com/dotnet/designs/blob/main/accepted/2020/better-obsoletion/binaryformatter-obsoletion.md)
  • Loading branch information
vbreuss committed Aug 24, 2023
1 parent 7024c22 commit 147462e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public TestingException(string message, Exception inner)
{
}

#if !NET8_0_OR_GREATER
/// <summary>
/// Initializes a new instance of <see cref="TestingException" /> for serialization.
/// <para />
Expand All @@ -35,4 +36,5 @@ protected TestingException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
#endif
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.IO;
#if !NET8_0_OR_GREATER
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using Testably.Abstractions.Testing.FileSystemInitializer;

Expand All @@ -18,15 +19,16 @@ public void
byte[] buffer = new byte[4096];
using MemoryStream ms = new(buffer);
using MemoryStream ms2 = new(buffer);
#pragma warning disable SYSLIB0011 //BinaryFormatter serialization is obsolete - only used in unit test
BinaryFormatter formatter = new();
#pragma warning disable SYSLIB0011 //BinaryFormatter serialization is obsolete - only used in unit test
formatter.Serialize(ms, originalException);
TestingException deserializedException =
(TestingException)formatter.Deserialize(ms2);
#pragma warning restore SYSLIB0011
#pragma warning restore SYSLIB0011

Assert.Equal(originalException.InnerException?.Message,
deserializedException.InnerException?.Message);
Assert.Equal(originalException.Message, deserializedException.Message);
}
}
#endif

0 comments on commit 147462e

Please sign in to comment.