-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Closed
dotnet/roslyn-analyzers
#6911Description
Analyzer
Diagnostic ID: CA2229: Implement serialization constructors
Analyzer source
Version: 8.0 preview 6
Describe the bug
In .NET 8, obsoletion warning SYSLIB0051 was introduced which added a warning to any type using Exception's .ctor(SerializationInfo, StreamingContext)
However, not implementing this .ctor lights up CA2229.
Steps To Reproduce
public class M : Exception // CA2229: Add a constructor to M with the following signature: 'protected M(SerializationInfo info, StreamingContext context)'.
{
public M(string? message) : base(message) { }
public M(string? message, Exception innerException) : base(message, innerException) { }
// protected M(SerializationInfo info, StreamingContext context) : base(info, context) { }
public M() { }
}
Expected behavior
Given the long term obsoletion strategy of binary serialization, this analyzer should probably be sunset, or perhaps only apply to .NET <8.
Actual behavior
Either CA2229
or SYSLIB0051
are triggered, depending on whether the commented code above is un-commented.
HamsterExAstris, alexrp and buyaa-n