ygoe / TxTranslation

Tx Translation & Localisation for .NET and WPF
GNU General Public License v3.0
28 stars 12 forks source link

Dictionary gets purged when another assembly gets loaded #22

Open codingdave opened 2 years ago

codingdave commented 2 years ago

TxLib stores its translations in a static dictionary. Imagine you have your application A.exe that uses TxLib.dll version A. Now A.exe has plugin support and can be enriched by the plugin B.dll. B.dll uses another version of TxLib.dll version B. The second the plugin reaches a method that access the static Tx.T fuction (or any other static function) TxLib.dll version B will get loaded and the static class constructor will initialize the static dictionary. This leads to a loss of translations for the loaded assembly TxLib.dll version A.

This issue is so apparent it even sometimes breaks unit tests that run in parallel, all using TxLib: In the instance another test accesses the static Tx.T function (or any other) the test itself cannot access the translation any longer.

I propose to add a non-static constructor and non static functions. Then the translation objects can live next to each other. For backward compatibility one could offer a static Default TxLib object, that uses the same non-static ctor and all static functions use that (static) instance.