Description
See this proposed solution
Pull request
When JavsScript is instructed to call back C# it should not throw an exception about duplicate identifiers when invoking an instance.
public class One
{
[JSInvokable]
public void DoSomething() {}
}
public class Two
{
[JSInvokable]
public void DoSomething() {}
}
In JavaScript the following code will throw an exception because there is more than one JSInvoke with the identifier "DoSomething"
window.someLibrary = {
callBackDoSomething: function(callback) {
callback.invokeMethodAsync("DoSomething");
}
}
This makes sense when invoking static methods on a static class, but when invoking on a DotNetObjectRef it makes sense to check for duplicate identifiers only on the class of the instance being passed.
This will save from having to write [JSInvokable("MyCompany.MyLibrary.One.DoSomething")]
and [JSInvokable("MyCompany.MyLibrary.Two.DoSomething")]
to ensure unique callback identifiers across multiple libraries when calling methods on instances (the above string format would still be recommented for static methods though).
In essence, the JSInvokableAttribute applied to a static method should be a globally unique identifier for the method, and on an instance method it should be treated as an alias for the method.
I'd be happy to rewrite the relevant code and submit a pull request if you are in agreement? The implementation I have in mind would also address https://github.com/aspnet/Blazor/issues/1557.