* dotnet/corefx#35491 Fixes issue with BinaryFormatter.Deserialize throwing other exceptions than those specified in the documentation (only supposed to throw SerializationException or SecurityException).
* Update UnitySerializationHolderTests to test the expected behaviour of BinaryFormatter.Deserialize. Fix naming error in SerializationGuardTests.
Commit migrated from https://github.com/dotnet/corefx/commit/
1736bfa5f06d4d3a60742142f0aaf601bd4db788
{
_crossAppDomainArray = _crossAppDomainArray
};
- var parser = new BinaryParser(serializationStream, reader);
- return reader.Deserialize(parser, check);
+ try
+ {
+ var parser = new BinaryParser(serializationStream, reader);
+ return reader.Deserialize(parser, check);
+ }
+ catch (SerializationException)
+ {
+ throw;
+ }
+ catch (Exception e)
+ {
+ throw new SerializationException(SR.Serialization_CorruptedStream, e);
+ }
}
+
public void Serialize(Stream serializationStream, object graph) =>
Serialize(serializationStream, graph, true);
ms.Position = 0;
BinaryFormatter reader = new BinaryFormatter();
- TargetInvocationException tie = Assert.Throws<TargetInvocationException>(() => reader.Deserialize(ms));
- Assert.IsAssignableFrom<SerializationException>(tie.InnerException);
+ SerializationException se = Assert.Throws<SerializationException>(() => reader.Deserialize(ms));
+ Assert.IsAssignableFrom<TargetInvocationException>(se.InnerException);
}
}
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Tests;
using Xunit;
public void UnitySerializationHolderWithAssemblySingleton()
{
const string UnitySerializationHolderAssemblyBase64String = "AAEAAAD/////AQAAAAAAAAAEAQAAAB9TeXN0ZW0uVW5pdHlTZXJpYWxpemF0aW9uSG9sZGVyAwAAAAREYXRhCVVuaXR5VHlwZQxBc3NlbWJseU5hbWUBAAEIBgIAAABLbXNjb3JsaWIsIFZlcnNpb249NC4wLjAuMCwgQ3VsdHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1iNzdhNWM1NjE5MzRlMDg5BgAAAAkCAAAACw==";
- AssertExtensions.Throws<ArgumentException>(() =>
+ SerializationException se = AssertExtensions.Throws<SerializationException>(() =>
BinaryFormatterHelpers.FromBase64String(UnitySerializationHolderAssemblyBase64String));
+ Assert.IsAssignableFrom<ArgumentException>(se.InnerException);
}
}
}