diff --git a/src/Microsoft.JSInterop/DotNetDispatcher.cs b/src/Microsoft.JSInterop/DotNetDispatcher.cs index 5612d9edcc..0f346bbfdd 100644 --- a/src/Microsoft.JSInterop/DotNetDispatcher.cs +++ b/src/Microsoft.JSInterop/DotNetDispatcher.cs @@ -240,7 +240,11 @@ namespace Microsoft.JSInterop var result = new Dictionary(); var invokableMethods = GetRequiredLoadedAssembly(assemblyName) .GetExportedTypes() - .SelectMany(type => type.GetMethods()) + .SelectMany(type => type.GetMethods( + BindingFlags.Public | + BindingFlags.DeclaredOnly | + BindingFlags.Instance | + BindingFlags.Static)) .Where(method => method.IsDefined(typeof(JSInvokableAttribute), inherit: false)); foreach (var method in invokableMethods) { diff --git a/test/Microsoft.JSInterop.Test/DotNetDispatcherTest.cs b/test/Microsoft.JSInterop.Test/DotNetDispatcherTest.cs index 315f26d832..eec537f987 100644 --- a/test/Microsoft.JSInterop.Test/DotNetDispatcherTest.cs +++ b/test/Microsoft.JSInterop.Test/DotNetDispatcherTest.cs @@ -155,6 +155,21 @@ namespace Microsoft.JSInterop.Test Assert.True(targetInstance.DidInvokeMyInvocableInstanceVoid); }); + [Fact] + public Task CanInvokeBaseInstanceVoidMethod() => WithJSRuntime(jsRuntime => + { + // Arrange: Track some instance + var targetInstance = new DerivedClass(); + jsRuntime.Invoke("unimportant", new DotNetObjectRef(targetInstance)); + + // Act + var resultJson = DotNetDispatcher.Invoke(null, "BaseClassInvokableInstanceVoid", 1, null); + + // Assert + Assert.Null(resultJson); + Assert.True(targetInstance.DidInvokeMyBaseClassInvocableInstanceVoid); + }); + [Fact] public Task CannotUseDotNetObjectRefAfterDisposal() => WithJSRuntime(jsRuntime => { @@ -376,6 +391,21 @@ namespace Microsoft.JSInterop.Test } } + public class BaseClass + { + public bool DidInvokeMyBaseClassInvocableInstanceVoid; + + [JSInvokable] + public void BaseClassInvokableInstanceVoid() + { + DidInvokeMyBaseClassInvocableInstanceVoid = true; + } + } + + public class DerivedClass : BaseClass + { + } + public class TestDTO { public string StringVal { get; set; }