dotnet / platform-compat

Roslyn analyzer that finds usages of APIs that will throw PlatformNotSupportedException on certain platforms.
MIT License
278 stars 43 forks source link

Exception(SerializationInfo info, StreamingContext context) flagged as not compatible #66

Closed danielmarbach closed 6 years ago

danielmarbach commented 6 years ago
    [Serializable]
    public class MessageDeserializationException : SerializationException
    {
...

        #pragma warning disable PC001
        protected MessageDeserializationException(SerializationInfo info, StreamingContext context) : base(info, context)
        {
        }
        #pragma warning restore PC001
    }

but it seems to be supported?

https://github.com/dotnet/coreclr/blob/release/2.0.0/src/mscorlib/shared/System/Runtime/Serialization/SerializationException.cs#L35

bording commented 6 years ago

Looking at this a bit more, the above code isn't enough to trigger a warning, however this does:

/// <summary>
/// <see cref="SerializationException(SerializationInfo, StreamingContext)" />
/// </summary>
public class MessageDeserializationException : SerializationException
{
    protected MessageDeserializationException(SerializationInfo info, StreamingContext context) : base(info, context)
    {
    }
}

It's actually the usage of SerializationException in the xml comment that seems to be causing the warning. As @danielmarbach said, I'm not seeing a reason why this would be flagged, so I think it's a false positive.

pjanotti commented 6 years ago

These methods to serialize exceptions were throwing PNSE in the past but eventually the fix was backported to 2.0 (see https://github.com/dotnet/platform-compat/issues/76#issuecomment-350378457).

Anyway, the xml thing here is interesting...

OliaG commented 6 years ago

In the scope of this issue, we will fix XML problem and version problem is handled in #77.

XML problem:

SerializationException causes warning "PC001 SerializationException.SerializationException(SerializationInfo, StreamingContext) isn't supported on Linux, MacOSX, Windows" when it's in XML:

/// <summary>
/// <see cref="SerializationException(SerializationInfo, StreamingContext)" />
/// </summary>

and does not cause warning when it is in the class body:

static void Main(string[] args)
        {
            var e = new SerializationException();
        }