Assembly.Location Property

Definition

Gets the full path or UNC location of the loaded file that contains the manifest.

C#
public virtual string Location { get; }

Property Value

The location of the loaded file that contains the manifest. If the assembly is loaded from a byte array, such as when using Load(Byte[]), the value returned is an empty string ("").

Implements

Exceptions

The current assembly is a dynamic assembly, represented by an AssemblyBuilder object.

Examples

The following example displays the location of the loaded file that contains the manifest.

C#
Assembly SampleAssembly;
// Instantiate a target object.
Int32 Integer1 = new Int32();
Type Type1;
// Set the Type instance to the target class type.
Type1 = Integer1.GetType();
// Instantiate an Assembly class to the assembly housing the Integer type.
SampleAssembly = Assembly.GetAssembly(Integer1.GetType());
// Display the physical location of the assembly containing the manifest.
Console.WriteLine("Location=" + SampleAssembly.Location);
// The example displays the following output:
//   Location=C:\Windows\Microsoft.NET\Framework64\v4.0.30319\mscorlib.dll

Remarks

In .NET 5 and later versions, for bundled assemblies, the value returned is an empty string.

.NET Framework only: If the loaded file was shadow-copied, the location is that of the file after being shadow-copied. To get the location before the file has been shadow-copied, use the CodeBase property.

Applies to

Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.5, 1.6, 2.0, 2.1

See also