0

Can anyone shed light on whether the exception message from a FileNotFoundException in .NET is displayed in the threads UI culture or if it is always in English (I'm suspecting it'll be their current UI culture)?

At present I'm checking for the string "The specified module could not be found." to help produce a more useful response to the user informing them that they are missing a third party library. Does anyone know what happens in other languages when a specified module is not detected?

Peter Wright
  • 79
  • 1
  • 7
  • Your code won't work, but you already knew that. It is a mistake in any language, everybody can google the .NET error message, find out what it means and figure out what to do about it. Nobody can google your message. – Hans Passant Feb 25 '16 at 10:08

3 Answers3

1

Instead of doing a string comparison of the message, you could instead check the HResult property and compare that. MOD_NOT_FOUND is 0x8007007E.

You can read more about it here and take a look at common HResult values here

edit

After some further research there is one thing I'd like to add: If you are on an older .NET version than .NET 4.5 you can't just obtain the HResult value, but need to call a method. Look here

Community
  • 1
  • 1
Steffen Winkler
  • 2,805
  • 2
  • 35
  • 58
0

The .NET framework contains localized exception messages. It seems reasonable for Microsoft to localize those framework exception messages, since their target audience can be located anywhere.

I would suggest that you catch the expected exception without doing a string comparison of the message, instead use the fact that you know you would get a FileNotFoundException in that scenario and then display a message to the user as you wanted.

Matthew Marlin
  • 316
  • 3
  • 11
0

The message is localized and you should not check for the String, but just check for an instance of FileNotFoundException in your code as you will not be able to catch it in any culture without a lot of effort and it might change in later versions.

In other languages also an instance of FileNotFoundException is thrown, with a localized message.