Open SarahCIPFA opened 8 months ago
I've turned on all debugging, but no matter what I do I can't break on the server and see what the details of the error are.
More information! It's a bug! (I think?)
The line shown (line 446) throws an error, and that error doesn't contain the relevant error details to enable rapid debugging. (The assembly name, and function name!)
As an exception has occurred already and we're not in a try/catch block, line 449 that checks for a duplicate attribute and reports the specific details never gets reached.
@SarahCIPFA thanks for contacting us.
That error seems to be for something else. In this case, I believe what's happening is that there are two instances of [JSInvokable]
applied to the same method and that's not correctly handled in the line that you point out.
I believe the other error is for something slightly different. It's very much likely covered in some unit test somewhere.
With this in mind, if you want to contribute a PR that fixes the issue and adds the relevant tests, we will be happy to consider it. However, please describe the concrete scenario in which you are running into this issue first so that we can make sure it's a valid scenario.
Looks like this issue has been identified as a candidate for community contribution. If you're considering sending a PR for this issue, look for the Summary Comment
link in the issue description. That comment has been left by an engineer on our team to help you get started with handling this issue. You can learn more about our Help Wanted process here
However, please describe the concrete scenario in which you are running into this issue first so that we can make sure it's a valid scenario.
(I see what you mean about there being two things going on; and that exception throw code isn't related to the issue I'm seeing with the plain JSInvoke.)
Sure! I'll do my best to make it readable. =) We've a small team of developers moving a mature 20 year .NET Framework project to Blazor. It consists of many projects, and lots of JSInvokable functions. Over the last few months we've discovered it's been quite easy to duplicate up these attributes, or corrupt them - something which the Roslyn compiler does not catch. They're very hard to find - we have to troll through checkins to see the point it broke, and then sieve through the relevant files.
I tried setting up debugging to break on the error, but without success (I'm not a debug expert by any means). What happened instead, was the invoked C# function caused a "Duplicate" error in DotNetDispatcher, without giving a line, or an assembly - the short error just gets returned to the JavaScript on the client - as can be seen in the debug screenshot.
The one major problem was - any issue in any Blazor page containing JSInvokes caused the error - because ALL assemblies are parsed during the invoke! So NO JSInvokable actions would work for any pages in that project.
The project will be around 1200 pages large when the conversion is complete, and getting a JSInvoke error in that lot.... well. As you can imagine something needed to be done.
I nearly went for a quick text scan, digg out issues using a custom cmd line application. But realised I could copy the bits out of DotNetDispatcher.cs I needed in it's own page on our site, and just open it. It worked well as a work around!
I believe a try{}catch() would suffice, and the throw report the relevant function name/assembly? I don't know of the MS specific way of catching this error, HResult code perhaps? (I'd be happy for someone else to check the change in, I've never done such before for a huge project like this!)
My bodge for debugging it isn't up to enterprise standards, as you can see!
Summary
Calling [JSInvokable] functions gives a very generic error if there's multiple of the same name. This is in Core 8
Motivation and goals
Could we have more details in the error sent back to the client for the JS Debugger?
In scope
One single duplicate can disable all the buttons in a project, and takes a long time to find.
Example:
[JSInvokable] public static Task<string[]> RoomTypeGridAddRow(string GridID, string GridControlState, string Token) {
Clicking a button on the client that invokes the above task can generate the error: Uncaught (in promise) Error: System.Reflection.AmbiguousMatchException: Multiple custom attributes of the same type 'Microsoft.JSInterop.JSInvokableAttribute' found.
System.Reflection.AmbiguousMatchException: Multiple custom attributes of the same type 'Microsoft.JSInterop.JSInvokableAttribute' found. at System.Attribute.GetCustomAttribute(MemberInfo element, Type attributeType, Boolean inherit) at System.Reflection.CustomAttributeExtensions.GetCustomAttribute[T](MemberInfo element, Boolean inherit) at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.ScanAssemblyForCallableMethods(AssemblyKey assemblyKey) at System.Collections.Concurrent.ConcurrentDictionary
2.GetOrAdd(TKey key, Func
2 valueFactory) at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.GetCachedMethodInfo(AssemblyKey assemblyKey, String methodIdentifier) at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.InvokeSynchronously(JSRuntime jsRuntime, DotNetInvocationInfo& callInfo, IDotNetObjectReference objectReference, String argsJson) at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.BeginInvokeDotNet(JSRuntime jsRuntime, DotNetInvocationInfo invocationInfo, String argsJson)I've checked the code at the following location, and it details the {identifier} in the exception! I don't know why we're receiving a much more generic error.