1

I am getting MissingManifestResourceException exception when trying to access the resx file.

I have one code snippet which works fine and I have another one which does not work. I am not sure what is going on here.

Working Snippet

static void Main(string[] args)
{
    //Keep an Eye on the first parameter I have passed, it has ".Lang" in it 
    var rm = new ResourceManager("ConsoleApp1.App_GlobalResources.Lang", Assembly.GetExecutingAssembly());
    var ci = Thread.CurrentThread.CurrentCulture;
    var a = rm.GetString("Name", ci);
    Console.WriteLine("Hello World!");
}

Non Working Snippet:

static void Main(string[] args)
{
    // Keep an eye on first parameter no ".Lang" here.
    var rm = new ResourceManager("ConsoleApp1.App_GlobalResources", Assembly.GetExecutingAssembly());
    var ci = Thread.CurrentThread.CurrentCulture;
    var a = rm.GetString("Name", ci);
    Console.WriteLine("Hello World!");
}

My Solution Structure:

enter image description here

Property of Lang.en-US file (Works Fine):

enter image description here

Property of en-US file (DO NOT Work):

enter image description here

Question 1: Why does Lang.en-US does not generate any .CS file, even then IT WORKS

Question 2: Why does a basic bare en-US.resx creates a .CS file and still does not work.

Link I looked into: SO LINK

Pic 1:

enter image description here

Pic 2:

enter image description here

Cœur
  • 37,241
  • 25
  • 195
  • 267
Unbreakable
  • 7,776
  • 24
  • 90
  • 171

1 Answers1

2

Your Working example works as follow.

  1. ResourceManager loads "Lang" as his virtual file prefix set.
  2. GetString(Key, Culture) - tries to look for the correct culture, if it doesn't find one, then it will fallback to none culture file. e.g: for 'en-US' it will try to find Lang.en-US.resx and will default to Lang.resx

Your Non-Working example doesn't work, because you don't give it a virtual file prefix, but a folder path.

Solution: One Ideal situation, is using your Working with the following multiple language files.

Language folder (i.e: App_GlobalResources [bad name])

  • Lang.resx: default for non existing cultures files
  • Lang.en-US.resx: en-US culture
  • Lang.he.resx: he culture
  • You can see the gist

Code:

var rm = new ResourceManager("ConsoleApp1.App_GlobalResources.Lang", Assembly.GetExecutingAssembly());
Orel Eraki
  • 11,940
  • 3
  • 28
  • 36