Skip to content

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

Closed

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

Activity

  1. changed the title [-]Fix AD0001: CertificateValidationCheck Syntax node is not within syntax tree[/-] [+]NET-3367 Fix AD0001: CertificateValidationCheck Syntax node is not within syntax tree[/+] on Mar 11, 2026
  2. github-actions commented on Mar 11, 2026

    @github-actions
    Contributor

    Internal ticket NET-3367

  3. changed the title [-]NET-3367 Fix AD0001: CertificateValidationCheck Syntax node is not within syntax tree[/-] [+]NET-3367 Fix S4830 AD0001: CertificateValidationCheck Syntax node is not within syntax tree[/+] on Mar 11, 2026
  4. alex-meseldzija-sonarsource commented on Mar 11, 2026

    @alex-meseldzija-sonarsource
    Contributor

    Hi @patrick-achtbytes , thanks for the report!

    I can confirm that this is an AD0001, we will try to fix this soon.

  5. alex-meseldzija-sonarsource commented on Mar 17, 2026

    @alex-meseldzija-sonarsource
    Contributor

    Hi @patrick-achtbytes,

    We have fixed this in the latest release of our analyzers. It is available now on SonarQube Cloud and will be available in the next SonarQube Server release.

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

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