Sometimes when writing texts describing an error that occurred in the code, we are faced with the fact that this text is duplicated from error to error in different blocks of code. Sometimes, when editing a code or if it is a banal desire to rephrase the text of the error written earlier, it becomes necessary to edit the text accompanying the error. Since the same text can be spread across several files, the editing process of the accompanying text error turns into pain.

  1. Is it possible to use resource files (.resx) in projects such as - .dll to store the text shown to the user when generating errors? (I know that technically it is possible in WPF. But I don’t know if there are any technical details when working with these files in .dll).
  2. Is it normal practice to use .resx files to store text errors?
  3. If possible, comment on the existing alternatives to simplify the work with duplicate text errors.

PS: I know that resource files (.resx) are for localization. I just want to hear opinions about the idea that has appeared in my head, which simplifies the work with the text of errors.

  • resx - for localization, not for eliminating duplication. Eliminating duplication is easier with subroutines or constants. - Pavel Mayorov
  • @PavelMayorov Would you recommend storing constants inside classes that indicate errors either in a separate file for the whole project? The second solution in the form of the implementation of the subprogrammes, to be honest, is hardly at all presented. Whether prompt there are any articles or examples? - Evgeniy Miroshnichenko
  • @PavelMayorov I somehow quickly turned back, after your comment on the appointment of .resx files, mentally discarding the idea. But he remembered that the text of errors shown to the end user sometimes also needs localization. So is it possible, however, the use of resource files is a normal alternative to constants? - Evgeniy Miroshnichenko
  • 2
    For localization purposes, yes, completely normal. Moreover, it is the official alternative to constants. - Pavel Mayorov

0