C# – Best practice: What is the best way to store exception/error or informational messages in C#.net for internationalization


When throwing custom exceptions or issuing messages to the end user, one could use hard-coded the strings (including string constants), use resource-only assemblies or get strings from a table in a database.

I would like my application to be able to switch to a different language easily without having to recompile. While storing the string resources in a assembly or database would achieve this purpose, it adds to the complexity of program logic which in turn adds to the cost of the product.

My question is: what is the best way to go with the objective in mind without ignoring the cost that comes with each option? If you have a practice that is better than what's been listed, I'd love to hear it.

OS: Windows family
Platform: .NET Frame 2 and up
Language: C#
Database: MS SQL 2005 and up

Thanks guys!


Best Solution

Use resources:

How does this add more complexity to the program logic?

   //do something with System.Net.Mail with invalid email..
catch (FormatException fex)
    throw new Exception(Resources.ErrorMsg.Invalid_Email, fex);


In VS2008 when you create a resource, you can define if its internal or public. So assume we set it to public, in an assembly called ClassLibrary1, we can access a property like:


Where InvalidError is the name of the error. Again I don't think this adds any compelxity to the logic.