Skip to content

Commit

Permalink
De-conflict with new JSON obsoletion codes
Browse files Browse the repository at this point in the history
- Also improve obsoletion messages
  • Loading branch information
GrabYourPitchforks committed Apr 5, 2023
1 parent 63e0dd6 commit 13e3ca7
Show file tree
Hide file tree
Showing 95 changed files with 451 additions and 451 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@
<!-- Warnings that should be disabled in our test projects. -->
<PropertyGroup Condition="'$(IsTestProject)' == 'true' or '$(IsTestSupportProject)' == 'true' or '$(IsPublishedAppTestProject)' == 'true'">
<!-- don't warn on usage of BinaryFormatter and legacy formatter infrastructure from test projects -->
<NoWarn>$(NoWarn);SYSLIB0011;SYSLIB0049;SYSLIB0050</NoWarn>
<NoWarn>$(NoWarn);SYSLIB0011;SYSLIB0050;SYSLIB0051</NoWarn>
<!-- don't warn about unnecessary trim warning suppressions. can be removed with preview 6. -->
<NoWarn>$(NoWarn);IL2121</NoWarn>
<!-- allow nullable annotated files to be incorporated into tests without warning -->
Expand Down
4 changes: 2 additions & 2 deletions docs/project/list-of-diagnostics.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ The PR that reveals the implementation of the `<IncludeInternalObsoleteAttribute
| __`SYSLIB0047`__ | XmlSecureResolver is obsolete. Use XmlResolver.ThrowingResolver instead when attempting to forbid XML external entity resolution. |
| __`SYSLIB0048`__ | RSA.EncryptValue and DecryptValue are not supported and throw NotSupportedException. Use RSA.Encrypt and RSA.Decrypt instead. |
| __`SYSLIB0049`__ | JsonSerializerOptions.AddContext is obsolete. To register a JsonSerializerContext, use either the TypeInfoResolver or TypeInfoResolverChain properties. |
| __`SYSLIB0049`__ | Legacy formatter-based serialization is obsolete and should not be used. See https://aka.ms/binaryformatter for more information. |
| __`SYSLIB0050`__ | (reserved) |
| __`SYSLIB0050`__ | Legacy formatter-based serialization is obsolete and should not be used. |
| __`SYSLIB0051`__ | This API supports legacy formatter-based serialization. It should not be called or extended by application code. |

## Analyzer Warnings

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ partial void RestoreRemoteStackTrace(SerializationInfo info, StreamingContext co
_watsonBuckets = (byte[]?)info.GetValueNoThrow("WatsonBuckets", typeof(byte[])); // Do not rename (binary serialization)

// If we are constructing a new exception after a cross-appdomain call...
#pragma warning disable SYSLIB0049 // StreamingContextStates is obsolete
#pragma warning disable SYSLIB0050 // StreamingContextStates is obsolete
if (context.State == StreamingContextStates.CrossAppDomain)
#pragma warning restore SYSLIB0049
#pragma warning restore SYSLIB0050
{
// ...this new exception may get thrown. It is logically a re-throw, but
// physically a brand-new exception. Since the stack trace is cleared
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1604,13 +1604,13 @@ internal static void GetCustomAttributes(RuntimeType type, RuntimeType caType, r
if (!all && !s_pca.Contains(caType))
return;

#pragma warning disable SYSLIB0049 // Legacy serialization infrastructure is obsolete
#pragma warning disable SYSLIB0050 // Legacy serialization infrastructure is obsolete
if (all || caType == typeof(SerializableAttribute))
{
if ((type.Attributes & TypeAttributes.Serializable) != 0)
pcas.Add(new SerializableAttribute());
}
#pragma warning restore SYSLIB0049
#pragma warning restore SYSLIB0050
if (all || caType == typeof(ComImportAttribute))
{
if ((type.Attributes & TypeAttributes.Import) != 0)
Expand All @@ -1623,13 +1623,13 @@ internal static bool IsDefined(RuntimeType type, RuntimeType? caType)
if (!all && !s_pca.Contains(caType!))
return false;

#pragma warning disable SYSLIB0049 // Legacy serialization infrastructure is obsolete
#pragma warning disable SYSLIB0050 // Legacy serialization infrastructure is obsolete
if (all || caType == typeof(SerializableAttribute))
{
if ((type.Attributes & TypeAttributes.Serializable) != 0)
return true;
}
#pragma warning restore SYSLIB0049
#pragma warning restore SYSLIB0050
if (all || caType == typeof(ComImportAttribute))
{
if ((type.Attributes & TypeAttributes.Import) != 0)
Expand Down Expand Up @@ -1756,13 +1756,13 @@ internal static void GetCustomAttributes(RuntimeFieldInfo field, RuntimeType caT
pca = GetFieldOffsetCustomAttribute(field);
if (pca is not null) pcas.Add(pca);
}
#pragma warning disable SYSLIB0049 // Legacy serialization infrastructure is obsolete
#pragma warning disable SYSLIB0050 // Legacy serialization infrastructure is obsolete
if (all || caType == typeof(NonSerializedAttribute))
{
if ((field.Attributes & FieldAttributes.NotSerialized) != 0)
pcas.Add(new NonSerializedAttribute());
}
#pragma warning restore SYSLIB0049
#pragma warning restore SYSLIB0050
}
internal static bool IsDefined(RuntimeFieldInfo field, RuntimeType? caType)
{
Expand All @@ -1778,13 +1778,13 @@ internal static bool IsDefined(RuntimeFieldInfo field, RuntimeType? caType)
{
if (GetFieldOffsetCustomAttribute(field) is not null) return true;
}
#pragma warning disable SYSLIB0049 // Legacy serialization infrastructure is obsolete
#pragma warning disable SYSLIB0050 // Legacy serialization infrastructure is obsolete
if (all || caType == typeof(NonSerializedAttribute))
{
if ((field.Attributes & FieldAttributes.NotSerialized) != 0)
return true;
}
#pragma warning restore SYSLIB0049
#pragma warning restore SYSLIB0050

return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ public sealed override IEnumerable<CustomAttributeData> CustomAttributes
}

FieldAttributes attributes = Attributes;
#pragma warning disable SYSLIB0049 // Legacy serialization infrastructure is obsolete
#pragma warning disable SYSLIB0050 // Legacy serialization infrastructure is obsolete
if (0 != (attributes & FieldAttributes.NotSerialized))
{
yield return new RuntimePseudoCustomAttributeData(typeof(NonSerializedAttribute), null);
}
#pragma warning restore SYSLIB0049
#pragma warning restore SYSLIB0050
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public sealed override int GetArrayRank()
protected sealed override TypeAttributes GetAttributeFlagsImpl()
{
TypeAttributes attrs = TypeAttributes.AutoLayout | TypeAttributes.AnsiClass | TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.Sealed;
#pragma warning disable SYSLIB0049 // Legacy serialization infrastructure is obsolete
#pragma warning disable SYSLIB0050 // Legacy serialization infrastructure is obsolete
attrs |= TypeAttributes.Serializable;
#pragma warning restore SYSLIB0049
#pragma warning restore SYSLIB0050
return attrs;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ public sealed override IEnumerable<CustomAttributeData> CustomAttributes
if (0 != (attributes & TypeAttributes.Import))
yield return new RuntimePseudoCustomAttributeData(typeof(ComImportAttribute), null);

#pragma warning disable SYSLIB0049 // Legacy serialization infrastructure is obsolete
#pragma warning disable SYSLIB0050 // Legacy serialization infrastructure is obsolete
if (0 != (attributes & TypeAttributes.Serializable))
yield return new RuntimePseudoCustomAttributeData(typeof(SerializableAttribute), null);
#pragma warning restore SYSLIB0049
#pragma warning restore SYSLIB0050
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/libraries/Common/src/System/Obsoletions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,10 @@ internal static class Obsoletions
internal const string JsonSerializerOptionsAddContextMessage = "JsonSerializerOptions.AddContext is obsolete. To register a JsonSerializerContext, use either the TypeInfoResolver or TypeInfoResolverChain properties.";
internal const string JsonSerializerOptionsAddContextDiagId = "SYSLIB0049";

internal const string LegacyFormatterMessage = "Legacy formatter-based serialization is obsolete and should not be used. See https://aka.ms/binaryformatter for more information.";
internal const string LegacyFormatterDiagId = "SYSLIB0049";
internal const string LegacyFormatterMessage = "Legacy formatter-based serialization is obsolete and should not be used.";
internal const string LegacyFormatterDiagId = "SYSLIB0050";

internal const string LegacyFormatterImplMessage = "Legacy formatter-based serialization (IMPL) is obsolete and should not be used. See https://aka.ms/binaryformatter for more information.";
internal const string LegacyFormatterImplDiagId = "SYSLIB0050";
internal const string LegacyFormatterImplMessage = "This API supports legacy formatter-based serialization. It should not be called or extended by application code.";
internal const string LegacyFormatterImplDiagId = "SYSLIB0051";
}
}
2 changes: 1 addition & 1 deletion src/libraries/Common/tests/System/MockType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ internal class MockType : Type
public override bool IsSecuritySafeCritical => throw Unexpected;
public override bool IsSecurityTransparent => throw Unexpected;
#if NET8_0_OR_GREATER
[Obsolete("Legacy formatter-based serialization is obsolete and should not be used. See https://aka.ms/binaryformatter for more information.", DiagnosticId = "SYSLIB0049", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
[Obsolete("Legacy formatter-based serialization is obsolete and should not be used.", DiagnosticId = "SYSLIB0050", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
#endif
public override bool IsSerializable => throw Unexpected;
public override bool IsSubclassOf(Type c) => throw Unexpected;
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/Microsoft.CSharp/ref/Microsoft.CSharp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public enum CSharpBinderFlags
public partial class RuntimeBinderException : System.Exception
{
public RuntimeBinderException() { }
[System.ObsoleteAttribute("Legacy formatter-based serialization (IMPL) is obsolete and should not be used. See https://aka.ms/binaryformatter for more information.", DiagnosticId = "SYSLIB0050", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
[System.ObsoleteAttribute("This API supports legacy formatter-based serialization. It should not be called or extended by application code.", DiagnosticId = "SYSLIB0051", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
protected RuntimeBinderException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
public RuntimeBinderException(string? message) { }
Expand All @@ -77,7 +77,7 @@ public RuntimeBinderException(string? message, System.Exception? innerException)
public partial class RuntimeBinderInternalCompilerException : System.Exception
{
public RuntimeBinderInternalCompilerException() { }
[System.ObsoleteAttribute("Legacy formatter-based serialization (IMPL) is obsolete and should not be used. See https://aka.ms/binaryformatter for more information.", DiagnosticId = "SYSLIB0050", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
[System.ObsoleteAttribute("This API supports legacy formatter-based serialization. It should not be called or extended by application code.", DiagnosticId = "SYSLIB0051", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
protected RuntimeBinderInternalCompilerException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
public RuntimeBinderInternalCompilerException(string? message) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1296,7 +1296,7 @@ public static void WriteAllText(string file, string text, bool append, System.Te
public partial class MalformedLineException : System.Exception
{
public MalformedLineException() { }
[System.ObsoleteAttribute("Legacy formatter-based serialization (IMPL) is obsolete and should not be used. See https://aka.ms/binaryformatter for more information.", DiagnosticId = "SYSLIB0050", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
[System.ObsoleteAttribute("This API supports legacy formatter-based serialization. It should not be called or extended by application code.", DiagnosticId = "SYSLIB0051", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
protected MalformedLineException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
public MalformedLineException(string? message) { }
Expand All @@ -1305,7 +1305,7 @@ public MalformedLineException(string? message, long lineNumber) { }
public MalformedLineException(string? message, long lineNumber, System.Exception? innerException) { }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Always)]
public long LineNumber { get { throw null; } set { } }
[System.ObsoleteAttribute("Legacy formatter-based serialization (IMPL) is obsolete and should not be used. See https://aka.ms/binaryformatter for more information.", DiagnosticId = "SYSLIB0050", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
[System.ObsoleteAttribute("This API supports legacy formatter-based serialization. It should not be called or extended by application code.", DiagnosticId = "SYSLIB0051", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public override void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
public override string ToString() { throw null; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Namespace Microsoft.VisualBasic.FileIO
''' <param name="context"></param>
''' <remarks></remarks>
' [Obsolete(Obsoletions.LegacyFormatterImplMessage, DiagnosticId = Obsoletions.LegacyFormatterImplDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
<Obsolete("Legacy formatter-based serialization (IMPL) is obsolete and should not be used. See https://aka.ms/binaryformatter for more information.", DiagnosticId:="SYSLIB0050", UrlFormat:="https://aka.ms/dotnet-warnings/{0}")>
<Obsolete("This API supports legacy formatter-based serialization. It should not be called or extended by application code.", DiagnosticId:="SYSLIB0051", UrlFormat:="https://aka.ms/dotnet-warnings/{0}")>
<EditorBrowsable(EditorBrowsableState.Never)>
Protected Sub New(ByVal info As System.Runtime.Serialization.SerializationInfo, ByVal context As System.Runtime.Serialization.StreamingContext)
MyBase.New(info, context)
Expand Down Expand Up @@ -108,7 +108,7 @@ Namespace Microsoft.VisualBasic.FileIO
''' <param name="context"></param>
''' <remarks></remarks>
' [Obsolete(Obsoletions.LegacyFormatterImplMessage, DiagnosticId = Obsoletions.LegacyFormatterImplDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
<Obsolete("Legacy formatter-based serialization (IMPL) is obsolete and should not be used. See https://aka.ms/binaryformatter for more information.", DiagnosticId:="SYSLIB0050", UrlFormat:="https://aka.ms/dotnet-warnings/{0}")>
<Obsolete("This API supports legacy formatter-based serialization. It should not be called or extended by application code.", DiagnosticId:="SYSLIB0051", UrlFormat:="https://aka.ms/dotnet-warnings/{0}")>
<EditorBrowsable(EditorBrowsableState.Never)>
Public Overrides Sub GetObjectData(ByVal info As System.Runtime.Serialization.SerializationInfo, ByVal context As System.Runtime.Serialization.StreamingContext)
If info IsNot Nothing Then ' Fix FxCop violation ValidateArgumentsOfPublicMethods.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ public partial class Win32Exception : System.Runtime.InteropServices.ExternalExc
public Win32Exception() { }
public Win32Exception(int error) { }
public Win32Exception(int error, string? message) { }
[System.ObsoleteAttribute("Legacy formatter-based serialization (IMPL) is obsolete and should not be used. See https://aka.ms/binaryformatter for more information.", DiagnosticId = "SYSLIB0050", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
[System.ObsoleteAttribute("This API supports legacy formatter-based serialization. It should not be called or extended by application code.", DiagnosticId = "SYSLIB0051", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
protected Win32Exception(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
public Win32Exception(string? message) { }
public Win32Exception(string? message, System.Exception? innerException) { }
public int NativeErrorCode { get { throw null; } }
[System.ObsoleteAttribute("Legacy formatter-based serialization (IMPL) is obsolete and should not be used. See https://aka.ms/binaryformatter for more information.", DiagnosticId = "SYSLIB0050", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
[System.ObsoleteAttribute("This API supports legacy formatter-based serialization. It should not be called or extended by application code.", DiagnosticId = "SYSLIB0051", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public override void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
public override string ToString() { throw null; }
Expand Down
Loading

0 comments on commit 13e3ca7

Please sign in to comment.