System.Resources.ResourceManager.GetObject Method

Gets the value of the specified non-string resource localized for the specified culture.


public virtual object GetObject (string name, System.Globalization.CultureInfo culture)


The name of the resource to get.
The culture for which the resource is localized. If the resource is not localized for this culture, the resource manager uses fallback rules to locate an appropriate resource.


The value of the resource, localized for the specified culture. If an appropriate resource set exists but name cannot be found, the method returns null.


The ResourceManager.GetObject(string, System.Globalization.CultureInfo) method is used to retrieve non-string resources. These include values that belong to primitive data types such as int or double, bitmaps (such as a System.Drawing.Bitmap object), or custom serialized objects. Typically, the returned object must be cast (in C#) or converted (in Visual Basic) to an object of the appropriate type.

The returned resource is localized for the culture that is specified by culture, or for the culture that is specified by the System.Globalization.CultureInfo.CurrentUICulture property if culture is null. If the resource is not localized for that culture, the resource manager uses fallback rules to load an appropriate resource. If no usable set of localized resources is found, the resource manager falls back on the default culture's resources. If a resource set for the default culture is not found, the method throws a System.Resources.MissingManifestResourceException exception or, if the resource set is expected to reside in a satellite assembly, a System.Resources.MissingSatelliteAssemblyException exception. If the resource manager can load an appropriate resource set but cannot find a resource named name, the method returns null.

The ResourceManager.IgnoreCase property determines whether the comparison of name with the names of resources is case-insensitive (the default) or case-sensitive.


This method can throw more exceptions than are listed. One reason this might occur is if a method that this method calls throws an exception. For example, a System.IO.FileLoadException exception might be thrown if an error was made deploying or installing a satellite assembly, or a System.Runtime.Serialization.SerializationException exception might be thrown if a user-defined type throws a user-defined exception when the type is deserialized.

Performance Considerations

If you call the erload:System.Resources.ResourceManager.GetObject method multiple times with the same name parameter, do not depend on the method returning a reference to the same object with each call. This is because the erload:System.Resources.ResourceManager.GetObject method can return a reference to an existing resource object in a cache, or it can reload the resource and return a reference to a new resource object.


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