C# WebException。状态未序列化
当我运行下面的测试(NUnit和VS2008 SP1)时,我得到以下错误 预期:连接失败C# WebException。状态未序列化,c#,exception,visual-studio-2008,serialization,deserialization,C#,Exception,Visual Studio 2008,Serialization,Deserialization,当我运行下面的测试(NUnit和VS2008 SP1)时,我得到以下错误 预期:连接失败 但事实是:未知错误 谁能解释我做错了什么 [Test] public void SerializationWebExceptionTest() { using (var stream = new MemoryStream()) { const WebExceptionStatus Expected = WebExceptionStatus.ConnectFailure;
但事实是:未知错误 谁能解释我做错了什么
[Test]
public void SerializationWebExceptionTest()
{
using (var stream = new MemoryStream())
{
const WebExceptionStatus Expected = WebExceptionStatus.ConnectFailure;
var formatter = new BinaryFormatter();
var initialException = new WebException("Test", null, Expected, null);
formatter.Serialize(stream, initialException);
stream.Seek(0, SeekOrigin.Begin);
var result = (WebException)formatter.Deserialize(stream);
var actual = result.Status;
Assert.That(actual, Is.EqualTo(Expected));
}
}
你做的一切都很好。在我看来,这似乎是.NET framework中的一个bug。在处理另一个AppDomain中抛出的异常时,在.NET4.6中偶然发现了这一点。 显示此字段的序列化代码已注释掉