Represents the information contained in an assembly manifest.
The AssemblyName
class represents the information contained in an assembly manifest. This includes the name, version, culture, and public key token of an assembly. It is commonly used when loading assemblies dynamically or querying assembly information.
public sealed class AssemblyName : ICloneable, System.Runtime.Serialization.ISerializable
Namespace: System.Reflection
Assembly: System.Runtime.dll
Object
AssemblyName
ICloneable
System.Runtime.Serialization.ISerializable
string
- Gets or sets the application or a fully qualified URL representing the Uniform Resource Locator (URL) that starts the assembly.
System.Globalization.CultureInfo
- Gets or sets the culture information for the assembly.
string
- Gets the application or a fully qualified URL representing the Uniform Resource Locator (URL) that starts the assembly, with special characters for URL encoding.
string
- Gets the full name of the assembly, including the version, culture, and public key token.
System.Configuration.Assemblies.AssemblyHashAlgorithm
- Gets or sets the hash algorithm used to hash the contents of the files in the assembly.
string
- Gets or sets the name of the assembly.
System.Reflection.ProcessorArchitecture
- Gets or sets the processor architecture for the assembly.
byte[]
- Gets or sets the public key for the assembly.
byte[]
- Gets the public key token for the assembly.
System.Version
- Gets or sets the version of the assembly.
object ICloneable.Clone()
- Creates a new AssemblyName object that is a copy of the current instance.
bool Equals(object obj)
- Determines whether the specified object is equal to the current object.
int GetHashCode()
- Serves as the default hash function.
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
- Populates a SerializationInfo object with the data needed to serialize the current AssemblyName object.
Type GetType()
- Gets the Type of the current instance.
string ToString()
- Returns a string that represents the current object.
The AssemblyName
class provides a rich set of properties to describe an assembly. It is crucial for scenarios involving assembly loading, binding, and resolution within the .NET runtime.
Key uses include:
Assembly.Load(AssemblyName)
.The FullName
property provides a concise, definitive string representation that can be used for assembly identification.
using System;
using System.Reflection;
public class Example
{
public static void Main(string[] args)
{
// Get the AssemblyName for the currently executing assembly
AssemblyName currentAssemblyName = Assembly.GetExecutingAssembly().GetName();
Console.WriteLine($"Assembly Name: {currentAssemblyName.Name}");
Console.WriteLine($"Version: {currentAssemblyName.Version}");
Console.WriteLine($"Full Name: {currentAssemblyName.FullName}");
if (currentAssemblyName.CultureInfo != null)
{
Console.WriteLine($"Culture: {currentAssemblyName.CultureInfo.Name}");
}
else
{
Console.WriteLine("Culture: Neutral");
}
}
}
using System;
using System.Reflection;
public class Example
{
public static void Main(string[] args)
{
// Example assembly name string
string assemblyNameString = "MyLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null";
try
{
AssemblyName assemblyName = new AssemblyName(assemblyNameString);
Console.WriteLine($"Parsed Name: {assemblyName.Name}");
Console.WriteLine($"Parsed Version: {assemblyName.Version}");
Console.WriteLine($"Parsed Full Name: {assemblyName.FullName}");
if (assemblyName.CultureInfo != null)
{
Console.WriteLine($"Parsed Culture: {assemblyName.CultureInfo.Name}");
}
else
{
Console.WriteLine("Parsed Culture: Neutral");
}
}
catch (ArgumentException ex)
{
Console.WriteLine($"Error parsing assembly name: {ex.Message}");
}
}
}
ArgumentException
: Thrown when the assembly name string is invalid or malformed.
FileNotFoundException
: Thrown when an assembly cannot be found.
BadImageFormatException
: Thrown when the assembly is not a valid executable assembly.