DotNetBrowser and invalid external method call

Recently I was debugging the issue with DotNetBrowser and external call from JavaScript. I had the following:

So I configure the browser and then set external object to handle callback. The callback is a method accepting two integers. It was called using this JS code:

It worked correctly on multiple machines for over a year. One day I ran the application on new machine and it stopped working. I added handler:

It showed dialog with mscorlib: Input string was not in a correct format. C# handler wasn’t called at all.

I attached dnSpy and it showed exception thrown in mscorlib Number.cs.

Okay, so what is wrong here? Notice that C# handler expects integers but JS doesn’t have them. So it passes numbers as doubles. It worked on one machine and didn’t work on the other so it immediately suggested there was something wrong with locales. Indeed, the former had English locale and the double was passed as 1.00000. The latter was running with Polish locale so it expected the coma and hence failed.

I don’t know exactly why it didn’t work but it wasn’t hard to fix it. First, change the C# handler to accept strings. Second, change JS code to pass the argument as window.external.NewMessagesCount("" + conversations.not(".muted").length, "" + conversations.length);