Tuesday, February 25, 2014

Find DLL location in Global Assembly Cache (GAC)

This method will give the location of an assembly from GAC



private string FindDLLInGAC(string dll)
{    foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies())
    {        if (a.ManifestModule.ScopeName.Equals(dll))
             return a.Location;
    }     return null; //Not found
}

//Usage
string asmLocation = FindDLLInGAC("TheDLL.dll");
Assembly asm = Assembly.LoadFile(asmLocation);
var thetype = asm.GetType(theType, true, false);

No comments: