I have a .resx file which contains some string resources for my project. At runtime, I’d like to read all of the resources defined in this file and store them in a container. The reason isn’t important.
I’ve read about the ResourceReader class, which operates on binary .resource files. My impression is that the .resx is converted to binary format on build and embedded in the assembly. Is this true, or do I need to manually generate it with resgen? If I do need to generate it manually, how do I add it to my VS project, embed it in the assembly, and access it at runtime?
In short, how can I access the resources defined in a .resx at runtime using a ResourceReader?
You can use ResourceReader.GetEnumerator() to get an enumerator to your resources.
If you’re tryign to read .resx files directly, you may want to consider using ResXResourceReader instead of ResourceReader.
If you’re trying to read from compiled in .resources (resx -> resources), you’ll need to modify the name appropriately. Say you name you .resX file ‘MyRes.resx’, you’ll want to use:
If the resx file is in a satellite assembly, though, it’ll add the project name, ie:
('MyProject.MyRes.resources');If you’re using localization, you’ll need that, too:
('MyProject.MyRes.en-GB.resources');