Assembly.CodeBase Свойство
Определение
Важно!
Некоторые сведения относятся к предварительной версии продукта, в которую до выпуска могут быть внесены существенные изменения. Майкрософт не предоставляет никаких гарантий, явных или подразумеваемых, относительно приведенных здесь сведений.
Получает расположение сборки, как указано первоначально, например, в объекте AssemblyName .
public:
virtual property System::String ^ CodeBase { System::String ^ get(); };
public virtual string CodeBase { get; }
member this.CodeBase : string
Public Overridable ReadOnly Property CodeBase As String
Значение свойства
Расположение сборки, указанной первоначально.
Реализации
Исключения
Только .NET Core и .NET 5+ : во всех случаях.
Примеры
В следующем примере используется CodeBase свойство.
using System;
using System.Reflection;
public class Example
{
public static void Main()
{
// Instantiate a target object.
Int32 integer1 = 1632;
// Instantiate an Assembly class to the assembly housing the Integer type.
Assembly systemAssembly = integer1.GetType().Assembly;
// Get the location of the assembly using the file: protocol.
Console.WriteLine("CodeBase = {0}", systemAssembly.CodeBase);
}
}
// The example displays output like the following:
// CodeBase = file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/mscorlib.dll
Imports System.Reflection
Module Example
Public Sub Main()
' Instantiate a target object.
Dim integer1 As Integer = 1632
' Instantiate an Assembly class to the assembly housing the Integer type.
Dim systemAssembly As Assembly = integer1.GetType().Assembly
' Get the location of the assembly using the file: protocol.
Console.WriteLine("CodeBase = {0}", systemAssembly.CodeBase)
End Sub
End Module
' The example displays output like the following:
' CodeBase = file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/mscorlib.dll
Комментарии
Чтобы получить абсолютный путь к загруженного файла, содержащего манифест, используйте Assembly.Location это свойство.
Если сборка была загружена в виде массива байтов, используя перегрузку Load метода, принимающего массив байтов, это свойство возвращает расположение вызывающего метода, а не расположение загруженной сборки.
В .NET 5 и более поздних версиях для пакетных сборок это свойство создает исключение.