Export (0) Print
Expand All

ResourceManager.BaseName Property

Gets the root name of the resource files that the ResourceManager searches for resources.

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

public virtual string BaseName { get; }

Property Value

Type: System.String
The root name of the resource files that the ResourceManager searches for resources.

The BaseName property reflects the fully qualified namespace name and the root resource name of a resource file, without its culture or file name extension. For example, if an app's default resource file is named SampleApps.StringResources.resources, the value of the BaseName property is "SampleApps.StringResources". If an app's default resource file is named SampleApps.StringResources.en-US.resources and is embedded in a satellite assembly, the value of the BaseName property is still "SampleApps.StringResources".

Important noteImportant

The BaseName property value of a resource file that is compiled and embedded from the command line does not include a namespace name unless you explicitly include one when compiling the file. On the other hand, the BaseName property value of a resource file that is compiled and embedded within the Visual Studio environment typically does include the default namespace name.

The BaseName property value is the same as the string passed to the ResourceManager(String, Assembly) or ResourceManager(String, Assembly, Type) constructor when instantiating a ResourceManager instance.

You can determine the names of embedded .resources files by compiling and running the following utility. This is a console app that accepts the name of a main assembly or satellite assembly as a command-line parameter. It displays the strings that should be provided as the baseName parameter of the ResourceManager(String, Assembly) or ResourceManager(String, Assembly, Type) constructor so that the resource manager can correctly identify the resource.

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

public class Example
{
   public static void Main()
   {
      if (Environment.GetCommandLineArgs().Length == 1) { 
         Console.WriteLine("No filename.");
         return;
      }

      string filename = Environment.GetCommandLineArgs()[1].Trim();
      // Check whether the file exists. 
      if (! File.Exists(filename)) {
         Console.WriteLine("{0} does not exist.", filename);
         return;
      }   

      // Try to load the assembly.
      Assembly assem = Assembly.LoadFrom(filename);
      Console.WriteLine("File: {0}", filename);

      // Enumerate the resource files. 
      string[] resNames = assem.GetManifestResourceNames();
      if (resNames.Length == 0)
         Console.WriteLine("   No resources found.");

      foreach (var resName in resNames)
         Console.WriteLine("   Resource: {0}", resName.Replace(".resources", ""));

      Console.WriteLine();
   }
}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0, 2.0, 1.0

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8
Show:
© 2015 Microsoft