Export (0) Print
Expand All

Assembly.CodeBase Property

Gets the location of the assembly as specified originally, for example, in an AssemblyName object.

[Visual Basic]
Public Overridable ReadOnly Property CodeBase As String
[C#]
public virtual string CodeBase {get;}
[C++]
public: __property virtual String* get_CodeBase();
[JScript]
public function get CodeBase() : String;

Property Value

The location of the assembly as specified originally.

Exceptions

Exception Type Condition
SecurityException The caller does not have the required permission.

Remarks

To get the absolute path to the loaded manifest-containing file, use the Assembly.Location property instead.

If the assembly was loaded as a byte array, this property returns the location of the caller of the Load method, not the assembly.

Example

The following example shows an expression that uses the CodeBase property.

[Visual Basic] 
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())
' Gets the location of the assembly using file: protocol.
Console.WriteLine(("CodeBase=" + SampleAssembly.CodeBase))
        End Sub 'Snippet1

[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());
// Gets the location of the assembly using file: protocol.
Console.WriteLine("CodeBase=" + SampleAssembly.CodeBase);

[C++] 
Assembly* SampleAssembly;
// Instantiate a target object.
Int32 Integer1(0);
Type* Type1;
// Set the Type instance to the target class type.
Type1 = __box(Integer1)->GetType();
// Instantiate an Assembly class to the assembly housing the Integer type.  
SampleAssembly = Assembly::GetAssembly(__box(Integer1)->GetType());
// Gets the location of the assembly using file: protocol.
Console::WriteLine(S"CodeBase= {0}", SampleAssembly->CodeBase);

[JScript] 
var SampleAssembly : Assembly;
// Instantiate a target object.
var Integer1 : Int32 = 0;
var Type1 : 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());
// Gets the location of the assembly using file: protocol.
Console.WriteLine("CodeBase=" + SampleAssembly.CodeBase);

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

.NET Framework Security: 

See Also

Assembly Class | Assembly Members | System.Reflection Namespace

Show:
© 2014 Microsoft