Skip to content
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

Fix S4027 FP: BinaryFormatter. Serialization constructors are obsolete and should not be required #8560

Closed
3 tasks done
martin-strecker-sonarsource opened this issue Jan 17, 2024 · 0 comments · Fixed by #8563
Assignees
Labels
Area: C# C# rules related issues. Type: False Positive Rule IS triggered when it shouldn't be.
Milestone

Comments

@martin-strecker-sonarsource
Copy link
Contributor

martin-strecker-sonarsource commented Jan 17, 2024

Description

In .net 8 "All externally visible (public or protected) serialization ctors: .ctor(SerializationInfo, StreamingContext)." are marked as obsolete (Source).

We need to remove the serialization constructor from the list of required constructors for exceptions.

Repro steps

public class MyException : Exception
{
      public MyException() { }

      public MyException(string message)
          :base(message) { }

      public MyException(string message, Exception innerException)
          : base(message, innerException) { }

      protected MyException(SerializationInfo info, StreamingContext context) // <- SYSLIB0051 
          : base(info, context) { }
}

Expected behavior

The serialization constructor should not be mandatory.

Actual behavior

A missing serialization constructor raises S4027.

Todos:

Known workarounds

Suppress S4027

See also

#8377

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: C# C# rules related issues. Type: False Positive Rule IS triggered when it shouldn't be.
Projects
None yet
3 participants