Name Property

AssemblyName.Name Property


Gets or sets the simple name of the assembly. This is usually, but not necessarily, the file name of the manifest file of the assembly, minus its extension.

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

public string Name { get; set; }

Property Value

Type: System.String

The simple name of the assembly.

The manifest file is the file that contains the assembly manifest.

For example, the simple name of a single-file assembly named "MyAssembly.dll" is "MyAssembly".

The following example emits a dynamic assembly and saves it to the current directory. When the assembly is created, the Name property is used to set the simple name of the dynamic assembly.

using System;
using System.Reflection;
using System.Threading;
using System.Reflection.Emit;

public class AssemblyName_Constructor
   public static void MakeAssembly(AssemblyName myAssemblyName, string fileName)
      // Get the assembly builder from the application domain associated with the current thread.
      AssemblyBuilder myAssemblyBuilder = Thread.GetDomain().DefineDynamicAssembly(myAssemblyName, AssemblyBuilderAccess.RunAndSave);
      // Create a dynamic module in the assembly.
      ModuleBuilder myModuleBuilder = myAssemblyBuilder.DefineDynamicModule("MyModule", fileName);
      // Create a type in the module.
      TypeBuilder myTypeBuilder = myModuleBuilder.DefineType("MyType");
      // Create a method called 'Main'.
      MethodBuilder myMethodBuilder = myTypeBuilder.DefineMethod("Main", MethodAttributes.Public | MethodAttributes.HideBySig |
         MethodAttributes.Static, typeof(void), null);
      // Get the Intermediate Language generator for the method.
      ILGenerator myILGenerator = myMethodBuilder.GetILGenerator();
      // Use the utility method to generate the IL instructions that print a string to the console.
      myILGenerator.EmitWriteLine("Hello World!");
      // Generate the 'ret' IL instruction.
      // End the creation of the type.
      // Set the method with name 'Main' as the entry point in the assembly.

   public static void Main()

      // Create a dynamic assembly with name 'MyAssembly' and build version ''.
      AssemblyName myAssemblyName = new AssemblyName(); 
      myAssemblyName.Name = "MyAssembly";
      myAssemblyName.Version = new Version("");
      MakeAssembly(myAssemblyName, "MyAssembly.exe");

      // Get all the assemblies currently loaded in the application domain.
      Assembly[] myAssemblies = Thread.GetDomain().GetAssemblies();

      // Get the dynamic assembly named 'MyAssembly'. 
      Assembly myAssembly = null;
      for(int i = 0; i < myAssemblies.Length; i++)
         if(String.Compare(myAssemblies[i].GetName().Name, "MyAssembly") == 0)
            myAssembly = myAssemblies[i];
      if(myAssembly != null)
         Console.WriteLine("\nDisplaying the assembly name\n");

Universal Windows Platform
Available since 4.5
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
© 2015 Microsoft