Assembly.Location 属性

定义

获取包含清单的已加载文件的完整路径或 UNC 位置。Gets the full path or UNC location of the loaded file that contains the manifest.

public:
 virtual property System::String ^ Location { System::String ^ get(); };
public virtual string Location { get; }
member this.Location : string
Public Overridable ReadOnly Property Location As String

属性值

String

包含清单的已加载文件的位置。The location of the loaded file that contains the manifest. 如果程序集是从字节数组加载的(例如使用时), Load(Byte[]) 则返回的值为空字符串 ( "" ) 。If the assembly is loaded from a byte array, such as when using Load(Byte[]), the value returned is an empty string ("").

实现

例外

当前的程序集是动态程序集,由 AssemblyBuilder 对象表示。The current assembly is a dynamic assembly, represented by an AssemblyBuilder object.

示例

下面的示例显示了包含清单的已加载文件的位置。The following example displays the location of the loaded file that contains the manifest.

Assembly^ SampleAssembly;
// Instantiate a target object.
Int32 Integer1(0);
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= {0}", SampleAssembly->Location );
// The example displays the following output:
//    Location=C:\Windows\Microsoft.NET\Framework64\v4.0.30319\mscorlib.dll  
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
Dim SampleAssembly As [Assembly]
' Instantiate a target object.
Dim Integer1 As New Int32()
Dim Type1 As Type
' 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

注解

在 .NET 5.0 和更高版本中,对于捆绑的程序集,返回的值是一个空字符串。In .NET 5.0 and later versions, for bundled assemblies, the value returned is an empty string.

仅 .NET Framework:如果已加载文件已进行 卷影复制,则该位置是该文件被影像复制后的位置。.NET Framework only: If the loaded file was shadow-copied, the location is that of the file after being shadow-copied. 若要在文件已进行卷影复制之前获取位置,请使用 CodeBase 属性。To get the location before the file has been shadow-copied, use the CodeBase property.

适用于