All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.plugins.csharp.S6798.html Maven / Gradle / Ivy

There is a newer version: 10.2.0.105762
Show newest version

Why is this an issue?

In Blazor, the [JSInvokable] attribute is used to annotate a method, enabling it to be invoked from JavaScript code. The prerequisite for this functionality is that the method must be declared as public.
Otherwise, a runtime error will be triggered when an attempt is made to call the method from JavaScript.

How to fix it

To fix the issue, ensure the methods annotated with the [JSInvokable] attribute are public.

Code examples

Noncompliant code example

@code {
    [JSInvokable]
    private static void MyStaticMethod() { } // Noncompliant

    [JSInvokable]
    internal void MyMethod() { } // Noncompliant
}

Compliant solution

@code {
    [JSInvokable]
    public static void MyStaticMethod() { } // Compliant

    [JSInvokable]
    public void MyMethod() { } // Compliant
}

Resources

Documentation





© 2015 - 2024 Weber Informatics LLC | Privacy Policy