Two DIFFERENT Blazor components define the following instance method:
[JSInvokable]
public void MyInstanceMethod()
{
...
}
At load time they call a js function, passing themselves to js:
await JS.InvokeAsync<object>("jsFunction", new DotNetObjectRef(this));
In js, the passed .NET object reference is saved in a variable named _callback. Later, an event occurring in javascript calls back the instance method
_callback.invokeMethodAsync("MyInstanceMethod");
The browser console fails with the following error:
blazor.webassembly.js:1 Uncaught (in promise) Error:
System.InvalidOperationException:
The assembly 'WebApplication7.Client' contains more than one [JSInvokable] method
with identifier 'MyInstanceMethod'.
All [JSInvokable] methods within the same assembly must have different identifiers.
BTW, everything goes well if only one component has the method.
Isn't this a violation of one of the fundamental scope features in any OO language?
Can anybody tell me why methods, including instance methods, are required to have different identifiers to be JSInvokable?
If this is a limit of Blazor, is there a plan to fix it?
[JSInvokable("MyComponent.MyInstanceMethod")]
overload would solve part of the issue for you?