runtime: Change exception returned when serializing HttpWebRequest to match NETFX

Comments from PR dotnet/corefx#18801:

From @safern “Binary Serialization is now supported on .NET Core 2.0 but it wasn’t in 1.1 or 1.0; so probably that is why we were throwing PNSE, so I think the same thing, it sounds reasonable to throw SE.”

        [Fact]
        public void HttpWebRequest_Serialize_Fails()
        {
            using (MemoryStream fs = new MemoryStream())
            {
                BinaryFormatter formatter = new BinaryFormatter();
                var hwr = HttpWebRequest.CreateHttp("http://localhost");

                if (PlatformDetection.IsFullFramework)
                {
                    // .NET Framework throws a more detailed exception.
                    // System.Runtime.Serialization.SerializationException):
                    //  Type 'System.Net.WebRequest+WebProxyWrapper' in Assembly 'System, Version=4.0.0.
                    //        0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable.
                    Assert.Throws<System.Runtime.Serialization.SerializationException>(() => formatter.Serialize(fs, hwr));
                }
                else
                {
                    // TODO: Issue dotnet/corefx#18850. Change HttpWebRquest to throw SerializationException similar to .NET Framework.
                    Assert.Throws<PlatformNotSupportedException>(() => formatter.Serialize(fs, hwr));
                }
            }
        }

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 1
  • Comments: 23 (23 by maintainers)

Most upvoted comments