ResourceManager Constructor (String, Assembly)

ResourceManager Constructor (String, Assembly)


Initializes a new instance of the ResourceManager class that looks up resources contained in files with the specified root name in the given assembly.

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

public ResourceManager(
	string baseName,
	Assembly assembly


Type: System.String

The root name of the resource file without its extension but including any fully qualified namespace name. For example, the root name for the resource file named MyApplication.MyResource.en-US.resources is MyApplication.MyResource.

Type: System.Reflection.Assembly

The main assembly for the resources.

Exception Condition

The baseName or assembly parameter is null.

In desktop apps, the individual culture-specific resource files should be contained in satellite assemblies, and the default culture's resource file should be contained in the main assembly. A satellite assembly is assumed to contain resources for a single culture specified in that assembly's manifest, and is loaded as necessary.


To retrieve resources from .resources files directly instead of retrieving them from assemblies, you must call the CreateFileBasedResourceManager method instead to instantiate a ResourceManager object.

If the resource file identified by baseName cannot be found in assembly, the method instantiates a ResourceManager object, but the attempt to retrieve a specific resource throws an exception, typically MissingManifestResourceException. For information about diagnosing the cause of the exception, see the "Handling the MissingManifestResourceException Exception" section of the ResourceManager class topic.


Although the ResourceManager class is supported in Windows 8.x Store apps, we do not recommend its use. Use this class only when you develop Portable Class Library projects that can be used with Windows 8.x Store apps. To retrieve resources from Windows 8.x Store apps, use the Windows.ApplicationModel.Resources.ResourceLoader class instead.

In Windows 8.x Store apps, the resource manager uses the simple name of the assembly parameter to look up a matching resource set in the app's package resource index (PRI) file. The baseName parameter is used to look up a resource item within the resource set. For example, the root name for is PortableLibrary1.Resource1.

Notes to Implementers:

This constructor uses the system-provided ResourceSet implementation. To use a custom resource file format, you should derive from the ResourceSet class, override the GetDefaultReader and GetDefaultWriter methods, and pass that type to the ResourceManager(String, Assembly, Type) constructor. Using a custom ResourceSet can be useful for controlling resource caching policy or supporting your own resource file format, but is generally not necessary.

The following example uses a simple non-localized "Hello World" app to illustrate the ResourceManager(String, Assembly) constructor. The following shows the contents of a text file named ExampleResources.txt. When the app is compiled, the resource is embedded in the main app assembly.


The text file can be converted to a binary resource file by using the at the command prompt as follows:

resgen ExampleResources.txt

The following example provides the executable code that instantiates a ResourceManager object, prompts the user to enter a name, and displays a greeting.

using System;
using System.Reflection;
using System.Resources;

public class Example
   public static void Main()
      // Retrieve the resource.
      ResourceManager rm = new ResourceManager("ExampleResources" , 
      string greeting = rm.GetString("Greeting");

      Console.Write("Enter your name: ");
      string name = Console.ReadLine();
      Console.WriteLine("{0} {1}!", greeting, name);
// The example produces output similar to the following:
//       Enter your name: John
//       Hello John!

It can be compiled by using the following command in Visual Basic:

vbc Example.vb /resource:ExampleResources.resources

or by using the following command in C#:

csc Example.cs /resource:ExampleResources.resources

Note that the example retrieves a reference to the assembly that contains the resource file by passing a type defined in that assembly to the typeof function (in C#) or the GetType function (in Visual Basic) and retrieving the value of its Type.Assembly property.

Universal Windows Platform
Available since 4.5
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
© 2015 Microsoft