System.Resources.ResXResourceReader Class

Enumerates XML resource (.resx) files and streams, and reads the sequential resource name and value pairs.

See Also: ResXResourceReader Members


public class ResXResourceReader : IResourceReader


The System.Resources.ResXResourceReader class provides a default implementation of the System.Resources.IResourceReader interface that reads resource information in an XML format. To read resource information from a binary resource format, use the System.Resources.ResourceReader class.

You use the System.Resources.ResXResourceReader class to enumerate resources in .resx files by traversing the dictionary enumerator (IDictionaryEnumerator) that is returned by the ResXResourceReader.GetEnumerator method. You call the methods provided by IDictionaryEnumerator to advance to the next resource and to read the name and value of each resource in the .resx file.


The System.Resources.ResXResourceReader class provides two enumerators. The ResXResourceReader.GetEnumerator method returns an IDictionaryEnumerator object; we recommend that you use this method to enumerate resources. The ResXResourceReader.System#Collections#IEnumerable#GetEnumerator method is an explicit interface implementation that returns an IEnumerator object; we do not recommend its use.

The following example uses the ResXResourceReader.GetEnumerator method to obtain an IDictionaryEnumerator object that is used to enumerate the resources in a .resx file. The example includes a CreateResourceFile routine that creates the necessary resource file.

code reference: System.Resources.ResXResourceReader.Class#1

If the ResXResourceReader.UseResXDataNodes property is true, the value of the IDictionaryEnumerator.Value property is a System.Resources.ResXDataNode object rather than the resource value. This makes a resource item's comment available from the ResXDataNode.Comment property. The following example sets the ResXResourceReader.UseResXDataNodes property to true and enumerates the resources in a .resx file,

code reference: System.Resources.ResXResourceReader.Class#2

If ResXResourceReader.UseResXDataNodes is true, the System.Resources.ResXDataNode items in the enumeration can be either:

If you want to retrieve named resources from a .resx file rather than enumerating its resources, you can instantiate a System.Resources.ResXResourceSet object and call its GetString and GetObject methods.


The System.Resources.ResXResourceReader class contains a link demand and an inheritance demand at the class level that applies to all members. A System.Security.SecurityException exception is thrown when either the immediate caller or the derived class does not have full-trust permission. For more information about security demands, see Link Demands and Inheritance Demands.


Namespace: System.Resources
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Assembly Versions: 1.0.5000.0,