-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
JSInvokableAttribute - No details on where the issue is. Undebuggable. #54646
Comments
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! 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 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 |
(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. =) I tried setting up debugging to break on the error, but without success (I'm not a debug expert by any means). 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? 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.
The text was updated successfully, but these errors were encountered: