AssemblyName.CultureInfo Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets or sets the culture that is supported by the assembly.

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

Syntax

'Declaration
Public Property CultureInfo As CultureInfo
public CultureInfo CultureInfo { get; set; }

Property Value

Type: System.Globalization.CultureInfo
The culture that is supported by the assembly.

Examples

This section contains two examples. The first example shows how to use the AssemblyName(String) constructor to parse a string that contains a full assembly name. The second example shows how to create an assembly name and use it to define a dynamic assembly.

Example 1

The following example gets the full name of a .NET Framework assembly, parses it by using the AssemblyName(String) constructor, and uses the properties and methods of AssemblyName to display the individual parts.

Imports System.Reflection

Public Class Example
   Private Const mask As Byte = 15

   Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)

      ' Use AssemblyName to parse full assembly names. In this example, the 
      ' assembly is mscorlib.dll.
      Dim name As String = GetType(String).Assembly.FullName
      Dim asmName As New AssemblyName(name) 

      outputBlock.Text &= String.Format("Name: {0}" & vbLf, asmName.Name)

      outputBlock.Text &= String.Format("Version: {0}" & vbLf, asmName.Version)

      outputBlock.Text &= String.Format("CultureInfo: {0}" & vbLf, asmName.CultureInfo)

      Dim pkt As New System.Text.StringBuilder()
      For Each b As Byte In asmName.GetPublicKeyToken()
          pkt.Append(Hex(b \ 16 And mask) & Hex(b And mask))
      Next b
      outputBlock.Text &= String.Format("PublicKeyToken: {0}" & vbLf, pkt.ToString())

      outputBlock.Text &= String.Format("FullName: {0}" & vbLf, asmName.FullName)

   End Sub

End Class

' This example produces output similar to the following:
'
'Name: mscorlib
'Version: 2.0.5.0
'CultureInfo: 
'PublicKeyToken: 7CEC85D7BEA7798E
'FullName: mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
using System;
using System.Reflection;

public class Example
{
   private const byte mask = 15;
   private const string hex = "0123456789ABCDEF";

   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      // Use AssemblyName to parse full assembly names. In this example, the 
      // assembly is mscorlib.dll.
      string name = typeof(string).Assembly.FullName;
      AssemblyName asmName = new AssemblyName(name);

      outputBlock.Text += String.Format("Name: {0}\n", asmName.Name);

      outputBlock.Text += String.Format("Version: {0}\n", asmName.Version);

      outputBlock.Text += String.Format("CultureInfo: {0}\n", asmName.CultureInfo);

      System.Text.StringBuilder pkt = new System.Text.StringBuilder();
      foreach( byte b in asmName.GetPublicKeyToken() )
      {
         pkt.Append(hex[b / 16 & mask]);
         pkt.Append(hex[b & mask]);
      }
      outputBlock.Text += String.Format("PublicKeyToken: {0}\n", pkt.ToString());

      outputBlock.Text += String.Format("FullName: {0}\n", asmName.FullName);
   }
}

/* This example produces output similar to the following:

Name: mscorlib
Version: 2.0.5.0
CultureInfo: 
PublicKeyToken: 7CEC85D7BEA7798E
FullName: mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
 */

Example 2

The following example emits a dynamic assembly. When the assembly is created, the CultureInfo property is used to specify the culture, which is part of the assembly's display name.

Imports System.Reflection
Imports System.Reflection.Emit

Public Class Example

   Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)

      ' Create an AssemblyName, set its properties, and use it to define a dynamic
      ' assembly.
      Dim aName As New AssemblyName("MyDynamicAssembly")
      aName.CultureInfo = New System.Globalization.CultureInfo("en-US")
      aName.Version = New Version("1.0.0.2001")

      Dim ab As AssemblyBuilder = _
         AppDomain.CurrentDomain.DefineDynamicAssembly(aName, _
                                                       AssemblyBuilderAccess.Run)
      Dim mb As ModuleBuilder = ab.DefineDynamicModule("Temp")
      Dim tb As TypeBuilder = mb.DefineType("Dummy", TypeAttributes.Public)

      Dim t As Type = tb.CreateType()

      outputBlock.Text &= String.Format("Assembly FullName: {0}" & vbLf, _
                                        t.Assembly.FullName) 
   End Sub
End Class

' This code example produces output similar to the following:
'
'Assembly FullName: MyDynamicAssembly, Version=1.0.0.2001, Culture=en-US, PublicKeyToken=null
using System;
using System.Reflection;
using System.Reflection.Emit;

public class Example
{
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      // Create an AssemblyName, set its properties, and use it to define a dynamic
      // assembly.
      AssemblyName aName = new AssemblyName("MyDynamicAssembly");
      aName.CultureInfo = new System.Globalization.CultureInfo("en-US");
      aName.Version = new Version("1.0.0.2001");

      AssemblyBuilder ab = 
         AppDomain.CurrentDomain.DefineDynamicAssembly(aName, AssemblyBuilderAccess.Run);
      ModuleBuilder mb = ab.DefineDynamicModule("Temp");
      TypeBuilder tb = mb.DefineType("Dummy", TypeAttributes.Public);

      Type t = tb.CreateType();

      outputBlock.Text += String.Format("Assembly FullName: {0}\n", t.Assembly.FullName);
   }
}

/* This code example produces output similar to the following:

Assembly FullName: MyDynamicAssembly, Version=1.0.0.2001, Culture=en-US, PublicKeyToken=null
 */

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.