Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RegisteredFunction.Invoke<T> should handle receiving 'null' for 'args' #16092

Closed
chanan opened this issue May 3, 2018 · 3 comments
Closed

RegisteredFunction.Invoke<T> should handle receiving 'null' for 'args' #16092

chanan opened this issue May 3, 2018 · 3 comments
Labels
area-blazor Includes: Blazor, Razor Components

Comments

@chanan
Copy link

chanan commented May 3, 2018

This is a bit strange.
This is my JS function:

Blazor.registerFunction('BlazorLogger.Logger.Count', function (label) {
    if (label !== null) console.count(label);
    else console.count();
    return true;
});

And defined these two interop functions:

public static void Count()
{
  RegisteredFunction.Invoke<bool>("BlazorLogger.Logger.Count", null);
}

public static void Count(string label)
{
  RegisteredFunction.Invoke<bool>("BlazorLogger.Logger.Count", label);
}

And calling it like so:

Logger.Count();
Logger.Count(null);
Logger.Count("bob");

Strangely, lines 2 & 3 work fine, but line 1 which seems to do more or less the same thing as line 2 does not:

Uncaught Error: System.ArgumentNullException: Value cannot be null.
Parameter name: source
  at System.Linq.Enumerable.Select[TSource,TResult] (:11690/System.Collections.Generic.IEnumerable`1[T] source, System.Func`2[T,TResult] selector) <0x1c01168 + 0x0001a> in <2e4578bfc56440cca13db140d3ae997a>:0 
  at Microsoft.AspNetCore.Blazor.Browser.Interop.RegisteredFunction.Invoke[TRes] (:11690/System.String identifier, System.Object[] args) <0x1c00820 + 0x00018> in <92ed9c6772a34798bccecc99cc26cbcd>:0 
  at :11690/BlazorLogger.Logger.Count () <0x1c003b0 + 0x00006> in <f4f92b4bec764f4ab07179cba15c0d18>:0 
  at :11690/Sample.Pages.Index.onclickCount () <0x1bff3b8 + 0x00004> in <0f6654494db343ba856c72c5c375f027>:0 
  at Microsoft.AspNetCore.Blazor.Components.EventHandlerInvoker.Invoke (:11690/Microsoft.AspNetCore.Blazor.UIEventArgs e) <0x1bff148 + 0x00076> in <0d9c96ffc9704aa9b088cbbe138126c6>:0 
...
@SteveSandersonMS SteveSandersonMS changed the title JS Interop doesnt work with a null argument in certain cases RegisteredFunction.Invoke<T> should handle receiving 'null' for 'args' May 3, 2018
@SteveSandersonMS
Copy link
Member

SteveSandersonMS commented May 3, 2018

Thanks for reporting this. The fix will be trivial.

@exostasis
Copy link

exostasis commented May 5, 2018

I would like to contribute to this project and start by resolving this issue. I checked PRs and didn't see anyone mention that they were fixing this. Since I would like to fix this issue I would like to also create a unit test for this bug but was unsure the right location to add the tests.

@SteveSandersonMS
Copy link
Member

We've changed the JS interop APIs in 0.5.0. RegisteredFunction.Invoke no longer exists, so I'll close this as outdated.

@mkArtakMSFT mkArtakMSFT transferred this issue from dotnet/blazor Oct 27, 2019
@mkArtakMSFT mkArtakMSFT added the area-blazor Includes: Blazor, Razor Components label Oct 27, 2019
@ghost ghost locked as resolved and limited conversation to collaborators Dec 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components
Projects
None yet
Development

No branches or pull requests

4 participants