Home All Groups Group Topic Archive Search About

Assembly.CodeBase // Getting it statically without object instantiation

Author
15 Aug 2006 8:55 PM
sloan
Here is the msdn code for getting the .CodeBase property of an Assembly

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);


Notice the "new Int32". (aka, an object instantiation)

Is there a way to statically get the Assembly.CodeBase ~without
instantiating an object ?

Take the simple example where you create a new/blank Console.Application.
How can I get the .CodeBase of that console app... remembering that I'm in
the
static world.. as such
static void Main(string[] args)

{



}

Author
15 Aug 2006 9:59 PM
David Browne
Show quote
"sloan" <sl***@ipass.net> wrote in message
news:eJdKV1KwGHA.4416@TK2MSFTNGP03.phx.gbl...
> Here is the msdn code for getting the .CodeBase property of an Assembly
>
> 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);
>
>
> Notice the "new Int32". (aka, an object instantiation)
>
> Is there a way to statically get the Assembly.CodeBase ~without
> instantiating an object ?
>
> Take the simple example where you create a new/blank Console.Application.
> How can I get the .CodeBase of that console app... remembering that I'm in
> the
> static world.. as such
> static void Main(string[] args)
>
> {
>
      Console.WriteLine(System.Reflection.Assembly.GetAssembly(typeof(Int32)).CodeBase);

>
>
> }
>
>

David
Author
16 Aug 2006 2:44 PM
sloan
I couldn't see the trees for the forest.

Thanks David.



Show quote
"David Browne" <davidbaxterbrowne no potted m***@hotmail.com> wrote in
message news:eZU%23cYLwGHA.4920@TK2MSFTNGP06.phx.gbl...
>
> "sloan" <sl***@ipass.net> wrote in message
> news:eJdKV1KwGHA.4416@TK2MSFTNGP03.phx.gbl...
> > Here is the msdn code for getting the .CodeBase property of an Assembly
> >
> > 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);
> >
> >
> > Notice the "new Int32". (aka, an object instantiation)
> >
> > Is there a way to statically get the Assembly.CodeBase ~without
> > instantiating an object ?
> >
> > Take the simple example where you create a new/blank
Console.Application.
> > How can I get the .CodeBase of that console app... remembering that I'm
in
> > the
> > static world.. as such
> > static void Main(string[] args)
> >
> > {
> >
>
Console.WriteLine(System.Reflection.Assembly.GetAssembly(typeof(Int32)).Code
Base);
Show quote
>
> >
> >
> > }
> >
> >
>
> David
>
>

AddThis Social Bookmark Button