Martin, one of my coworkers encountered a rather peculiar bug yesterday.

When calling C# code from Javascript using the window.external object, a rather strange thing happens. What happens when doing this is that all the parameters getting passed from Javascript to C# are passed as strings, which is not normally and issue.

Brace yourself….the problem is something that will sneak up on you when you least expect it.

The issue arises, when a foreign language version of Microsoft Office (in which the application runs as an add-in) is used, the Boolean parameters getting passed from the Javascript to the C# code are being translated. Essentially, what this means is that if you are running the German version of office, then if you pass a Boolean value to C# using window.external, then the resultant string gives you “wahr” and “falsch” instead of “true” and “false”.

Why on earth would the system decide that these internal values should be translated is utterly beyond me. It makes no sense at all as to why you would want to do that. Surely, at a programming level, values like true or false should be consistently represented, no matter what language your system is using.

As for a workaround, you can either convert the Boolean values to integer values such as 0 and 1, or, a better option, explicitly convert the Boolean values to a string and then pass that as a parameter to the window.external function call. You see, the translation engine leaves strings alone, unlike the Boolean values which get translated, so true and false will then be returned correctly, as the C# application would be expecting a string value in any event.

Share