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.
Assembly: mscorlib (in mscorlib.dll)
- 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.
The baseName or assembly parameter is a null reference (Nothing in Visual Basic).
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.
Windows Store Apps
Although the ResourceManager class is supported in Windows 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 Store apps. To retrieve resources from Windows Store apps, use the Windows.ApplicationModel.Resources.ResourceLoader class instead.
In Windows 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.
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 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 Resource File Generator (ResGen.exe) at the command prompt as follows:
The following example provides the executable code that instantiates a ResourceManager object, prompts the user to enter a name, and displays a greeting.
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.
.NET FrameworkSupported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1
.NET Framework Client ProfileSupported in: 4, 3.5 SP1
XNA FrameworkSupported in: 3.0, 2.0, 1.0
Portable Class LibrarySupported in: Portable Class Library
Supported in: Windows Phone 8.1
Supported in: Windows Phone Silverlight 8.1
Supported in: Windows Phone Silverlight 8