Skip to content

NET-3367 Fix S4830 AD0001: CertificateValidationCheck Syntax node is not within syntax tree #9795

@patrick-achtbytes

Description

@patrick-achtbytes

Description

When getting the certificate validation callback from a static method of a static class in a separate file which in turn calls another static method, the CertificateValidationCheck analyzer crashes with a System.ArgumentException: Syntax node is not within syntax tree (presumably because it can't find the method).

Workaround: Putting the validation class in the same file as it is used in, no error occurs.

Reproducer

Program.cs:

using var test = new SslStream(new MemoryStream(), false, CertValidator.GetCallback());

CertValidator.cs:

public static class CertValidator
{
    public static RemoteCertificateValidationCallback? GetCallback()
    {
        return (s, cert, chain, errors) =>
        {
            return Validate(errors);
        };
    }

    private static bool Validate(SslPolicyErrors errors)
    {
        return errors == SslPolicyErrors.None;
    }
}

Product and Version

NuGet SonarAnalyzer.CSharp 10.20.0.135146

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugExceptions and blocking issues during analysis.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions