How to embed, and get resources from Satellite Assembly In .NET MVC site for multiple locales

549 Views Asked by At

STEP 1: OK,I know I have read every page on the net about this so I finally broke down and ended up here at SOF.

Here is my resource file code:

using (ResourceWriter rw = new ResourceWriter(@"C:\pathto\errors.resources"))
{
  rw.AddResource("String1", "en-US");
}

So obviously, now i have my errors.resources file created w/the string resource named String1, w/the value of "en-US" in it.

STEP 2: So then after that I simply create my satellite assembly with:

c:\>al /t:lib /culture:en-US /embed:C:\pathto\errors.resources /out:C:\pathto\bin\en-US\MyWeb.Ext.errors.resources.dll

Ok...so cool.

STEP 3: So now in my project:

Thread.CurrentThread.CurrentCulture = newCulture;
Thread.CurrentThread.CurrentUICulture = newCulture;
ResourceManager rm = new ResourceManager("MyWeb.Ext.errors", this.GetType().Assembly);
ViewData["String1"] = rm.GetString("String1");

But no matter what I do...I can not access that string resource in the assembly. I can include my errors.resources file in the project and get it that way, but I need it to be in this assembly so I can use this assembly for another project too!

Can someone tell me what I might be doing wrong on step 3?? Or maybe I did something wrong in a prior step??

1

There are 1 best solutions below

2
On

Where is your resource file located relative to your assembly? You should create a directory containing the name of the locale the resource file is for (en-US in your case), and then place the satellite assembly in there. This directory should be in the same directory as the original assembly.