A method that script code is to invoke is not public, so the call from script fails at run time
What it finds
Blazor calls a [JSInvokable] method from JavaScript by reflection over public methods only: on a private, protected or internal method the call from script fails at run time with an error that names no such method. Methods marked [JSInvokable] must be public.
From the rule's source, js_invokable_not_public.rs.
using System.Threading.Tasks;using Microsoft.JSInterop; public class Interop{ [JSInvokable] private static Task<int> Count() => Task.FromResult(1);tx0 reports: [JSInvokable] method Count is not public [JSInvokable("Notify")] internal void Notify(string text)tx0 reports: [JSInvokable] method Notify is not public { } [JSInvokable] public void Resize(int width) { } private void Helper() { }} public interface ICallbacks{ [JSInvokable] void Done();} Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/csharp:js-invokable-not-public" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/csharp:js-invokable-not-public] reason="..."tx0 explain tx0/csharp:js-invokable-not-public shows the same in the terminal. Found a false positive? Report it.