AnsweredAssumed Answered

Loading swdocumentmgr api  dynamically

Question asked by Patrick Janvier on Feb 12, 2020
Latest reply on Feb 13, 2020 by Artem Taturevych

In our company we use different swdocumentmgr api version. We are planning to make one application irrespective api version and so we are using the below code


public List<string> result;
public string sLicenseKey = "xxxxxxxx";

public Dictionary<string, Type> dict = new Dictionary<string, Type>();
public Dictionary<string, Type> dictI = new Dictionary<string, Type>();
public Dictionary<string, Type> dictEnum = new Dictionary<string, Type>();

public void GetNames()

var DLL = Assembly.LoadFile(@".............\SolidWorks.Interop.swdocumentmgr.dll");

foreach (Type type in DLL.GetExportedTypes())
if (!type.IsInterface && !type.IsAbstract && !type.IsEnum)
dict.Add(type.Name, type);

if (type.IsInterface)
dictI.Add(type.Name, type);

if (type.IsEnum)
dictEnum.Add(type.Name, type);


dynamic swClassFact = Activator.CreateInstance(dict.Where(s => s.Key == "SwDMClassFactoryClass").Select (s => s.Value).First());
dynamic nDocType = Activator.CreateInstance(dictEnum.Where(s => s.Key == "SwDmDocumentType").Select(s => s.Value).First()).GetType();
dynamic nDocType1 = ((MemberInfo[])((TypeInfo)nDocType).DeclaredMembers)[4];// nDocType.GetRuntimeField("swDmDocumentDrawing");
dynamic nRetVal = Activator.CreateInstance(dictEnum.Where(s => s.Key == "SwDmDocumentOpenError").Select(s => s.Value).First()).GetType();
dynamic nRetVal1 = ((MemberInfo[])((TypeInfo)nRetVal).DeclaredMembers)[1];

string sDocFileName = @"C:\test\330555-PRD.SLDDRW";
dynamic swDocMgr = swClassFact.GetApplication(sLicenseKey);
dynamic swSearchOpt = swDocMgr.GetSearchOptionObject();
bool readonlyparameter = false;
dynamic swDoc = swDocMgr.GetDocument(sDocFileName,nDocType1, readonlyparameter, out nRetVal1);



  but we are encountering the below error at the last line of the above code


Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'The best overloaded method match for 'SolidWorks.Interop.swdocumentmgr.SwDMApplicationClass.GetDocument(string, SolidWorks.Interop.swdocumentmgr.SwDmDocumentType, bool, out SolidWorks.Interop.swdocumentmgr.SwDmDocumentOpenError)' has some invalid arguments'


Can anyone guide us to resolve the issue?



Patrick CJ