How can I get the source path of referenced assembly?

  • Thread starter Thread starter Leo Pedeglorio
  • Start date Start date
L

Leo Pedeglorio

Hi Everyone!

How can I get the source path of referenced assembly?

Source path - it is where the reference assembly or dll will be searched
when the solution is being rebuild.
You can see it when you right click a referenced assembly under a project
and select properties from the
context menu. From the properties window, there you will see the source
path.
But I want to get it inside my code. But how?

Thanks a lot!
 
Location property of System.Reflection.Assembly class will help you find the
path of the assembly.

regards
Kapil
 
The source path of a referenced assembly is never a part of the assembly
metadata(manifest). The actual path of the referenced assembly is only
resolved at rutime (which in itself is a complicated process) and this is
what is available through reflection. So, you may be loading an referenced
assembly different from the one which you have referenced (located in a
different folder) at runtime.

For getting a list of referenced assemblies, you may want to look at the
collection got from [Assembly].GetExecutingAssembly.GetReferencedAssemblies
method.
 
Apologies for my rather confusing sentance below. Here's the correction:

So, at runtime, you may be loading an assembly different from the one which
you have referenced at design time (located in a different folder/maybe
GAC).


--
HTH,
Manoj G [.NET MVP]
Site: http://www15.brinkster.com/manoj4dotnet
Blog: http://msmvps.com/manoj/

Manoj G said:
The source path of a referenced assembly is never a part of the assembly
metadata(manifest). The actual path of the referenced assembly is only
resolved at rutime (which in itself is a complicated process) and this is
what is available through reflection. So, you may be loading an referenced
assembly different from the one which you have referenced (located in a
different folder) at runtime.

For getting a list of referenced assemblies, you may want to look at the
collection got from [Assembly].GetExecutingAssembly.GetReferencedAssemblies
method.

--
HTH,
Manoj G [.NET MVP]
Site: http://www15.brinkster.com/manoj4dotnet
Blog: http://msmvps.com/manoj/

Kapil Sachdeva said:
Location property of System.Reflection.Assembly class will help you find the
path of the assembly.

regards
Kapil
 
Hi!

Assembly.GetReferencedAssemblies will return you an array of AssemblyName.
Use the CodeBase property of AssemblyName to get the path to the assembly in
question.

Ofcourse, if Configuration Policies are in place and they redirect calls to
a different assembly, then you wont get the redirected-to-assembly name.

--
Regards,
Kumar Gaurav Khanna
-----------------------------------------------------------------
Microsoft MVP - C#/.NET, MCSE Windows 2000/NT4, MCP+I
WinToolZone - Spelunking Microsoft Technologies
http://www.wintoolzone.com/
OpSupport - Spelunking Rotor
http://opsupport.sscli.net/
Bangalore .NET Users' Group
http://groups.msn.com/bdotnet/
 
Back
Top