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

Resolve the SYSLIB0051 obsoletion warning reported on DataServiceClientException #3183

Open
gathogojr opened this issue Feb 18, 2025 · 0 comments

Comments

@gathogojr
Copy link
Contributor

The following kinds of APIs are obsolete, starting in .NET 8. Calling them in code generates warning SYSLIB0051 at compile time.

DataServiceClientException inherits from InvalidOperationException and currently generates warnings because of the obsolete APIs.

We need to consider whether we really need to have the class serializable. Exception serialization is primarily intended to support remoting. Determine if that's something we really need.

The recommendation is to obsolete the serialization constructor and GetObjectData methods using the SYSLIB0051 diagnostic code - [Obsolete(DiagnosticId = "SYSLIB0051")]. Nobody is expected to be calling these APIs, obsoletion should only impact other types that subclass DataServiceClientException. It should not virally impact anybody catching, constructing, or otherwise using DataServiceClientException. Also consider removing the [Serializable] attribute. Both the built-in OData serialization logic and System.Text.Json don't depend or require the attribute.

Alternatively, we could drop the obsolete constructor and GetObjectData method from DataServiceClientException.

Below are the warning observed from the build logs:

Warning CS0672: Member 'DataServiceClientException.GetObjectData(SerializationInfo, StreamingContext)' overrides obsolete member 'Exception.GetObjectData(SerializationInfo, StreamingContext)'. Add the Obsolete attribute to 'DataServiceClientException.GetObjectData(SerializationInfo, StreamingContext)'

Warning SYSLIB0003: 'SecurityPermissionAttribute' is obsolete: 'Code Access Security is not supported or honored by the runtime.' (https://aka.ms/dotnet-warnings/SYSLIB0003)

Warning SYSLIB0003: 'SecurityAction' is obsolete: 'Code Access Security is not supported or honored by the runtime.' (https://aka.ms/dotnet-warnings/SYSLIB0003)

Warning SYSLIB0051: 'InvalidOperationException.InvalidOperationException(SerializationInfo, StreamingContext)' is obsolete: 'This API supports obsolete formatter-based serialization. It should not be called or extended by application code.' (https://aka.ms/dotnet-warnings/SYSLIB0051)

Warning SYSLIB0051: 'Exception.GetObjectData(SerializationInfo, StreamingContext)' is obsolete: 'This API supports obsolete formatter-based serialization. It should not be called or extended by application code.' (https://aka.ms/dotnet-warnings/SYSLIB0051)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant