GQL017: Could not find method

Value
Rule ID GQL017
Category Usage
Default severity Error
Enabled by default Yes
Code fix provided No
Introduced in v8.1

Cause

This rule is triggered when one of the following attributes specify a method name that doesn't exist on the specified type:

  • Validator
  • Parser
  • ValidateArguments

Rule description

The Validator, Parser, and ValidateArguments attributes serve as extension points when defining the schema using a type-first approach. These attributes enable method selection by specifying the type and method name. This diagnostic is triggered when the method with the specified name cannot be found on the designated type.

How to fix violations

Create the method with specified name, fix the attribute arguments or rename the method to match the arguments.

Example of a violation

public class TestClass
{
    [Parser(typeof(Parsers), "Parse")]
    public string Hello { get; set; }
}

public static class Parsers
{
    public static object ParseValue(object value) => value;
}

Example of how to fix

Fix the attribute argument to match the method name

public class TestClass
{
    [Parser(typeof(Parsers), "ParseValue")]
    public string Hello { get; set; }
}

public static class Parsers
{
    public static object ParseValue(object value) => value;
}

Suppress a warning

If you just want to suppress a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.

#pragma warning disable GQL017
// The code that's violating the rule is on this line.
#pragma warning restore GQL017

To disable the rule for a file, folder, or project, set its severity to none in the configuration file.

[*.cs]
dotnet_diagnostic.GQL017.severity = none

For more information, see How to suppress code analysis warnings.

GQL018: Parser method must be valid
GQL019: Validator method must be valid
GQL020: ValidateArguments method must be valid