Skip to content

CA2229 conflicts with the new SYSLIB0051 #90783

@RenderMichael

Description

@RenderMichael

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions