Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CRM 2011, ILMerge and localization

I'm having some trouble merging the localization satellite assemblies into the plugin DLL for CRM2011.

Either that, or I don't know how to use the merged resources afterwards.

I create a few plugins and create a basic resource file (default - English) and one for a specific culture (at the time of writing it's for Polish localizations, but later I'll need to add French as well).

I make sure not to sign the assembly itself, as ILMerge will sign the finished assembly itself.

This is the command I use to merge the extra satellite assembly:

ilmerge /targetplatform:v4,C:\Windows\Microsoft.NET\Framework\v4.0.30319 /log:log.txt /keyfile:KeyFile.snk /out:Plugins.dll DynamicsCRM2011.Plugins.dll pl-PL\DynamicsCRM2011.Plugins.resources.dll

As you can see, the plugins are in .NET 4.0 and I've got the required .config file for ILMerge to use the required assemblies for merging.

The generated file appears fine, I can register it with CRM plugin-registrator, add new steps and so forth.

However, it will always use the default language. I've tried changing the System.Threading.Thread.CurrentThread.UICulture, but this didn't help. When I created a ResourceManager class and used GetString("ErrorMessage", new System.Globalization.CultureInfo("pl-PL")), I got an Exception that the specified ResourceManager doesn't know what to do with the specified culture.

I know of this question here. However, the posted solution seems to be an old one. The generated resource .cs files do not use a ComponentResourceManager. Also, parts of the code posted there have been marked as deprecated.

I'm not really sure what I'm am to do now, or how to further debug this, as I have very little experience when it comes to working with assemblies themselves. Please, help me get those satellite assemblies under control.


Update:

I've been working with sandbox plugins for a while now, and thus I no longer have access to things such as CurrentCulture (or at least I cannot change such things). I've tried tackling this problem once more: I've created a simple plugin which is fired when a new Account is saved. Nothing fancy. Here's the actual plugin code:

        ResourceManager rm = new ResourceManager(typeof(Properties.Resources));
        var s = rm.GetString("ErrorAlreadyPosted", new System.Globalization.CultureInfo("pl-PL"));
        throw new InvalidPluginExecutionException(s);

The code no longer throws an exception about not being able to find the specified culture... also the code obviously throws an exception at the end, but the important thing is WHAT the exception message is. I'd expect it to be in Polish.

Alas, it is not. The string returned by GetString is still in English.

The command I used for ILmerge is the same as before, but with the /lib parameter specified so that I don't have to copy all the CRM SDK dlls...

like image 826
Shaamaan Avatar asked Nov 13 '22 14:11

Shaamaan


1 Answers

Apparently it is not possible to read resources from with the context of a Plugin.

Read up on MSDN: http://msdn.microsoft.com/en-us/library/hh670609.aspx#BKMK_UseXMLWebResourcesAsLanguageResources

Quote: When a plug-in requires localized text, you can use an XML web resource to store the localized strings so the plug-in can access them when needed. The structure of the XML is your option, but you may want to follow the structure used by ASP.NET Resource (.resx) files to create separate XML web resources for each language. For example, the following is an XML web resource named localizedString.en_US that follows the pattern used by .resx files.

This is all I know so far - have yet to build my own solution for localization of a crm plugin.

like image 171
ueberboss Avatar answered Jan 21 '23 04:01

ueberboss