Menu

Keep Blazor JS interop working after obfuscation
πŸ“°

Keep Blazor JS interop working after obfuscation

DEV Community: blazorΒ·Zero HeartbeatΒ·10 days ago
#ImPLxHQ7
#devtoblazor#devto#dev#strings#blob
Long article (1379 words) β€” no AI summary yet.
Reading 0:00
15s threshold

A Blazor app ships, obfuscated, and a button that worked all through development now fails in production:

Microsoft.JSInterop.JSException: The assembly 'MyApp' does not contain a public invokable method with [JSInvokable("ComputeTotal")].

Enter fullscreen mode

Exit fullscreen mode

The method is still there. It is still public . It still carries [JSInvokable] . The call still works in an un-obfuscated build. The only thing that changed is that a renaming pass turned ComputeTotal into a . That one rename broke a contract that lives half in .NET and half in a JavaScript string literal β€” and the fix tells you something precise about where Blazor keeps the name it matches against.

The real question

JavaScript calls into .NET by name :

const total = await DotNet . invokeMethodAsync ( 'MyApp' , 'ComputeTotal' , [ 1 , 2 , 3 ] ) ;

Enter fullscreen mode

Exit fullscreen mode

Two strings cross the boundary: the assembly's simple name and a method identifier .…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.