Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

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)

new : 
        baseName:string *
        assembly:Assembly -> ResourceManager

Parameters

baseName
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.

assembly
Type: System.Reflection.Assembly

The main assembly for the resources.

Exception Condition
ArgumentNullException

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.

System_CAPS_noteNote

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.

System_CAPS_importantImportant

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 PortableLibrary1.Resource1.de-DE.resources 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.

Greeting=Hello

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.

No code example is currently available or this language may not be supported.

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 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
Show:
© 2016 Microsoft