Search code examples
c#winformsmultilingual

Multilingual WinForms application do not work with .NET 2.0


I'm trying develop a sample application with multi language files.
I use: Windows 7 64bit and Visual Studio 2012 Express.
I read a few tutorials on the web, and I created a sample app.

In my Debug directory I created folders for language files: 'en' and 'pl'
I created text resource files in these directories and in the main directory, so my file structure is:

lang.txt
lang.resouces
multilang.resources.dll
multilang.exe
-en
--lang.en.txt
--lang.en.resources
--multilang.resources.dll
-pl
--lang.pl.txt
--lang.pl.resources
--multilang.resources.dll

I wrote a .bat file to embed satellite assemblies do my app resgen lang.txt al.exe /t:lib /embed:lang.resources /culture:pl-PL /out:multilang.resources.dll

resgen en/lang.en.txt
al.exe /t:lib /embed:en/lang.en.resources,multilang.en.resources /culture:en /out:en/multilang.resources.dll

resgen pl/lang.pl.txt
al.exe /t:lib /embed:pl/lang.pl.resources,multilang.pl.resources /culture:pl /out:pl/multilang.resources.dll

In my application I use ResourceManager

_rm = new ResourceManager("multilang", Assembly.GetExecutingAssembly());

and the GetString method to obtain text

this._rm.GetString(stringFromRm);

It works fine when I compile my App in the .NET 4.5 Framework, but when I change the Target framework in Project properties to .NET 2.0 I always get this exception:

System.Resources.MissingManifestResourceException

My app must work on Windows XP, so it must work with earlier .NET Framework versions.

Could somebody tell me what I must change to run my app on .NET Framework 2.0 ?


Solution

  • When running resgen.exe or al.exe for an application that should run on .NET framework, you must make sure that generated assemblies can be read by .NET 2.0 runtime. Assembly format has been extended in .NET 4, so the 2.0 runtime is to able to load 4.0 assemblies.

    So make sure that you're using both tools from C:\Windows\Microsoft.NET\Framework\v2.0.50727 and not from a newer framework version.