I am working on a project where I have to figure out what version of AutoCAD is installed in the target computer. We have considered the possibility of presence of multiple version of AutoCAD and thus, according to user choice, we have to dynamically load required DLLs from that version of AutoCAD. At first, the program discovers the available versions of AutoCAD and shows it to the User. Then, after selection of a specific version, the program copies DLLs like (accoremgd.dll, acdbmgd.dll, acmgd.dll) to the program directory. But when I try to load those dll dynamically, it shows following error:
Could not load file or assembly 'accoremgd.dll' or one of its dependencies. The specified module could not be found.
StackTrace:
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) at System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark) at System.Reflection.Assembly.LoadFrom(String assemblyFile) at DynamicDLLAdd.Form1.btnLoad_Click(Object sender, EventArgs e) in e:\AutoCadOperations\Test.AutoCadLoad_Re\DynamicDLLAdd\Form1.cs:line 140
My sub-routine which dynamically loads the file is:
try
{
string destFile = @Path.Combine(Environment.CurrentDirectory,"accoremgd.dll");
if (!File.Exists(destFile))
return;
Assembly a = null;
a = Assembly.LoadFrom(destFile);
AppDomain.CurrentDomain.Load(a.GetName());
MessageBox.Show("LOADED");
Type classType = a.GetType("Autodesk.AutoCAD.ApplicationService.Document");
object obj = Activator.CreateInstance(classType);
MethodInfo mi = classType.GetMethod("Create");
//rest of the code here
}
catch (Exception exp)
{
MessageBox.Show(exp.Message);
MessageBox.Show(exp.Source);
MessageBox.Show(exp.StackTrace);
}
I think the problem might with the dll's dependencies. What should be done? Is there any documents or articles available?
Update: The program's Target Framework is 4.0 and Platform target is Any CPU.
I ran fuselogvw.exe and I think here might be some clue to my problem. I have no idea what is going on here so, I have added a picture. It would be a great help if clarifies it.