Google+ Peter Bromberg's .NET Blog | How to get an assembly's location on the fly

Peter Bromberg's .NET Blog All Things Programming

How to get an assembly's location on the fly

9. August 2017 13:30 by admin in

 

private string[] GetAssemblyLocation(string[] assemblyNames){string[] locations = new string[assemblyNames.Length];for (int loop = 0; loop <= assemblyNames.Length - 1; loop++){locations[loop] = AppDomain.CurrentDomain.GetAssemblies().Where(a => !a.IsDynamic && a.ManifestModule.Name == assemblyNames[loop]).Select(a => a.Location).FirstOrDefault();}return locations;}


USAGE:

string reportPath = GetAssemblyLocation(new string[] { "Reports.dll" })[0];
  System.Reflection.Assembly assembly = Assembly.LoadFrom( reportPath);

 

Add comment

  Country flag


Loading