-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
CA2229
conflicts with the new SYSLIB0051
#90783
Comments
Moving to runtime repo to get this triaged. |
FYI @buyaa-n |
Tagging subscribers to this area: @dotnet/area-meta Issue DetailsAnalyzerDiagnostic ID: CA2013: Analyzer sourceVersion: 8.0 preview 6 Describe the bugIn .NET 8, obsoletion warning SYSLIB0051 was introduced which added a warning to any type implementing Exception's .ctor(SerializationInfo, StreamingContext) However, not implementing this .ctor lights up CA2229. Steps To Reproducepublic 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 behaviorGiven the long term obsoletion strategy of binary serialization, this analyzer should probably be sunset, or perhaps only apply to .NET <8. Actual behaviorEither
|
Removing the analyzer sounds good to me, what you think @GrabYourPitchforks, and probably need to ported to 8.0 CC @jeffhandley |
Since
I presume we'd also need to reconsider CA2237: Mark ISerializable types with SerializableAttribute and CA2235: Mark all non-serializable fields as well. What do you recommend, @GrabYourPitchforks? Thanks a bunch for reporting this, @RenderMichael!! |
Always glad! This issue would come up for every user with |
CA2235 strikes me as still useful. If you've slapped CA2237 should probably be changed to say that if you have implemented the |
Regarding how to resolve this conflict, we will need to consider folks who have explicitly turned |
The analyzer severity could be tied to the feature switch for binary serialization Ultimately, this does not need a detailed analysis because types like |
That warning probably only matter for to .Net framework users + .Net core users that turned on the switch for binary serialization, it seems Net framework users could use the NetAnalyzers from nuget, in that case I guess they would still want to the diagnostics, correct me if I am wrong @mavasani @stephentoub.
Interesting, but not sure if we could check within analyzer if a user turned on a feature switch at compile time CC @mavasani
Looks CA2235 doesn't work properly on .NET Core/netstandard (because the [Serializable] attribute not included in reference assemblies), therefore CA2235 is bail out on .NET Core/netstandard. Both analyzers CA2235 and CA2237 are disabled by default and marked as candidate for removal. Is that would change your suggestion @GrabYourPitchforks? |
Solution proposal:
Please let me know if you have other thoughts/comments @GrabYourPitchforks @jeffhandley @mavasani @RenderMichael @stephentoub. |
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
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
orSYSLIB0051
are triggered, depending on whether the commented code above is un-commented.The text was updated successfully, but these errors were encountered: