问题
I have been searching for a long time but the topic seems to be quite special. I didn't come up with anything. Maybe the specialists arounf here can help me.
I run a Windows Service which accesses some databases and does some calculation. If something fails, then that will result in an entry in a log file. My wish is to lacalize these entries. This worked fine with every project so far except for this Windows Service.
I use the resource manager and localized resources files. During runtime the CultureInfo is changed by:
Thread.CurrentThread.CurrentUICulture = new CultureInfo(this.language);
where language is a value read from the config file. The changes are veryfied at the next line:
LogService.WriteEntry(CultureInfo.CurrentUICulture.Name, EventLogEntryType.Information);
This works and returns the correct CultureInfo. The resources files are named correctly but still, the localized file (in that case "de") can't be accessed and the default (english) file is used. I added the resource files to the project output in the setup project.
Edit: In other Projects, the following worked fine, but not for the Windows Service:
ResourceManager locRM = new ResourceManager("WindowsService.ResWindowsService", Assembly.GetExecutingAssembly());
It seems the Windows Service just can't find the satellite assembly and then falls back to the neutral resource file which seems to be within the Windows Service exe file. Has anyone an idea how i can get the Windows Service to find the satellite assembly.
Edit 2: THE SOLUTION
A dear colleague helped. I strongly named the satellite assembly and registered it in the GAC. That was the solution. Now the Windows Service can access it. Detailed steps: In the setup project's file system editor: Add special folder -> Global assembly cache folder. Add file -> I added the resource file here Then under Project Properties -> Signing mark "Sign the Assembly" and create a new key file.
That's it.
Thanks, Nils
来源:https://stackoverflow.com/questions/6999835/localizing-windows-service