ResourceWriter Class


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Writes resources in the system-default format to an output file or an output stream. This class cannot be inherited.

Namespace:   System.Resources
Assembly:  mscorlib (in mscorlib.dll)


public sealed class ResourceWriter : IResourceWriter, IDisposable


Initializes a new instance of the ResourceWriter class that writes the resources to the provided stream.


Initializes a new instance of the ResourceWriter class that writes the resources to the specified file.


Gets or sets a delegate that enables resource assemblies to be written that target versions of the .NET Framework prior to the .NET Framework 4 by using qualified assembly names.

System_CAPS_pubmethodAddResource(String, Byte[])

Adds a named resource specified as a byte array to the list of resources to be written.

System_CAPS_pubmethodAddResource(String, Object)

Adds a named resource specified as an object to the list of resources to be written.

System_CAPS_pubmethodAddResource(String, Stream)

Adds a named resource specified as a stream to the list of resources to be written.

System_CAPS_pubmethodAddResource(String, Stream, Boolean)

Adds a named resource specified as a stream to the list of resources to be written, and specifies whether the stream should be closed after the Generate method is called.

System_CAPS_pubmethodAddResource(String, String)

Adds a string resource to the list of resources to be written.

System_CAPS_pubmethodAddResourceData(String, String, Byte[])

Adds a unit of data as a resource to the list of resources to be written.


Saves the resources to the output stream and then closes it.


Allows users to close the resource file or stream, explicitly releasing resources.


Determines whether the specified object is equal to the current object.(Inherited from Object.)


Saves all resources to the output stream in the system default format.


Serves as the default hash function. (Inherited from Object.)


Gets the Type of the current instance.(Inherited from Object.)


Returns a string that represents the current object.(Inherited from Object.)

ResourceWriter provides a default implementation of the IResourceWriter interface. It enables you to programmatically create a binary resource (.resources) file.

Resources are specified as name and value pairs using the AddResource method. Resource names are case-sensitive when used for lookups, but to more easily support authoring tools and help eliminate bugs, ResourceWriter will not allow a .resources file to have names that vary only by case. The ResourceWriter class enables you to create string, object, and binary resources. Binary resources can be written to the resource file as a byte array or a stream.


This type implements the IDisposable interface. When you have finished using the type, you should dispose of it either directly or indirectly. To dispose of the type directly, call its Dispose method in a try/catch block. To dispose of it indirectly, use a language construct such as using (in C#) or Using (in Visual Basic). For more information, see the “Using an Object that Implements IDisposable” section in the IDisposable interface topic.

To create a resources file, create a ResourceWriter with a unique file name, call AddResource at least once, call Generate to write the resources file to disk, and then call Close to close the file. Calling Close will implicitly call Generate if you do not explicitly call Generate.

The resources will not necessarily be written in the same order they were added.

To retrieve resources from a binary .resources file created by the ResourceWriter class, you can use the ResourceManager class, which lets you retrieve named resources, or the ResourceReader class, which lets you enumerate all the resources in the file.

The following example writes several strings into the myResources.resources file.

using System;
using System.Resources;

public class WriteResources {
   public static void Main(string[] args) {

      // Creates a resource writer.
      IResourceWriter writer = new ResourceWriter("myResources.resources");

      // Adds resources to the resource writer.
      writer.AddResource("String 1", "First String");

      writer.AddResource("String 2", "Second String");

      writer.AddResource("String 3", "Third String");

      // Writes the resources to the file or stream, and closes it.

.NET Framework
Available since 1.1

Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top