Skip to content

Instantly share code, notes, and snippets.

@luisdeol
Created March 20, 2017 22:09
Show Gist options
  • Save luisdeol/c047724997f7a40bf943e4cc2c7e2cd2 to your computer and use it in GitHub Desktop.
Save luisdeol/c047724997f7a40bf943e4cc2c7e2cd2 to your computer and use it in GitHub Desktop.
Simple Console Application to show how to access Assembly Referencies of a single Assembly through Reflection using C#.
using System;
using System.Reflection;
namespace TestingReflection
{
public class Program
{
static void Main(string[] args)
{
/* To get access to the PublicKeyToken of an Assembly you need to execute sn.exe and pass the Assembly path.
For example, I used this command to retrieve the PublicKeyToken from System.Data assembly
"C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\sn.exe" -T "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\System.Data.dll"
*/
var assembly =
Assembly.Load("System.Data, version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
var referencedAssemblies = assembly.GetReferencedAssemblies();
foreach (var reference in referencedAssemblies)
{
Console.WriteLine($"Assembly Name {reference.FullName}");
Console.WriteLine($"Assembly Version {reference.Version}");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment