Assembly.Location Assembly.Location Assembly.Location Assembly.Location Property

定义

获取包含清单的已加载文件的完整路径或 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

属性值

包含清单的已加载文件的位置。The location of the loaded file that contains the manifest. 如果已加载文件使用了影像复制,则该位置是该文件被影像复制后的位置。If the loaded file was shadow-copied, the location is that of the file after being shadow-copied. 如果从字节数组加载程序集(如使用 Load(Byte[]) 方法重载时),则返回值为空字符串 ("")。If the assembly is loaded from a byte array, such as when using the Load(Byte[]) method overload, 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

注解

若要在文件已进行卷影复制之前获取位置, 请使用CodeBase属性。To get the location before the file has been shadow-copied, use the CodeBase property.

安全性

FileIOPermission
用于访问路径。for access to the path. 关联的枚举:PathDiscoveryAssociated enumeration: PathDiscovery

适用于

另请参阅