简体   繁体   中英

Can't load resx file in code

I have a C# library (MyApp.ServiceLayer) and I want to access a common resx (/Resources/global.en-GB.resx) file from another library (MyApp.Common). I've added a reference from ServiceLayer to Common.

In the /bin/Debug folder of ServiceLayer I have (amongst others):

  • MyApp.Common.dll
  • en-gb/MyApp.Common.resources.dll.
  • /Resources/global.en-GB.resx

Reflector tells me that MyApp.Common.resources.dll has a Resources folder and a resource file: MyApp.Common.Resources.global.en-GB.resources

This code returns "could not load assembly" error.

ResourceManager resource = new ResourceManager("resources.global", Assembly.Load(new AssemblyName("MyApp.Common.resource")));

Why can't I get to it?

The loading by AssemblyName only works if the resource file has been loaded into the current AppDomain.

Use the method LoadFrom() instead of Load() to load the assembly from a file:

ResourceManager resource = new ResourceManager("resources.global", Assembly.LoadFrom(@"C:\full\path\of\the\assembly\MyApp.Common.resources.dll"));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM