-
Notifications
You must be signed in to change notification settings - Fork 5k
BinaryFormatter deprecation for System.Configuration.ConfigurationManager #50531
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we also care about adding a test case using reflection as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think in general we don't care about binary formatter usage if it is called explicitly via reflection by a user. |
||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Configuration; | ||
using Microsoft.DotNet.RemoteExecutor; | ||
using Xunit; | ||
|
||
namespace System.ConfigurationTests | ||
{ | ||
public class BinaryFormatterDeprecationTests | ||
{ | ||
private static bool AreBinaryFormatterAndRemoteExecutorSupportedOnThisPlatform => PlatformDetection.IsBinaryFormatterSupported && RemoteExecutor.IsSupported; | ||
|
||
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "SettingsSerializeAs.Binary is deprecated only on Core")] | ||
[Fact] | ||
public void ThrowOnSettingsPropertyConstructorWithSettingsSerializeAsBinary() | ||
{ | ||
#pragma warning disable CS0618 // Type or member is obsolete | ||
Assert.Throws<NotSupportedException>(() => new SettingsProperty("Binary", typeof(byte[]), null, false,"AString", SettingsSerializeAs.Binary, new SettingsAttributeDictionary(), true, true)); | ||
#pragma warning restore CS0618 // Type or member is obsolete | ||
} | ||
|
||
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "SettingsSerializeAs.Binary is deprecated only on Core")] | ||
[ConditionalFact(nameof(AreBinaryFormatterAndRemoteExecutorSupportedOnThisPlatform))] | ||
public void SerializeAndDeserializeWithSettingsSerializeAsBinary() | ||
{ | ||
RemoteInvokeOptions options = new RemoteInvokeOptions(); | ||
options.RuntimeConfigurationOptions.Add("System.Configuration.ConfigurationManager.EnableUnsafeBinaryFormatterInPropertyValueSerialization", bool.TrueString); | ||
RemoteExecutor.Invoke(() => | ||
{ | ||
#pragma warning disable CS0618 // Type or member is obsolete | ||
SettingsProperty property = new SettingsProperty("Binary", typeof(string), null, false, "AString", SettingsSerializeAs.Binary, new SettingsAttributeDictionary(), true, true); | ||
#pragma warning restore CS0618 // Type or member is obsolete | ||
SettingsPropertyValue value = new SettingsPropertyValue(property); | ||
value.PropertyValue = "AString"; // To force _changedSinceLastSerialized to true to allow for serialization in the next call | ||
object serializedValue = value.SerializedValue; | ||
Assert.NotNull(serializedValue); | ||
value.Deserialized = false; | ||
object deserializedValue = value.PropertyValue; | ||
Assert.Equal("AString", deserializedValue); | ||
}, options).Dispose(); | ||
} | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.