AnsweredAssumed Answered

Unable to cast SwDMconfiguration into SwDMconfiguration2

Question asked by Stephane Bonnet on Nov 9, 2018
Latest reply on Nov 12, 2018 by Stephane Bonnet

Here is my code. I wish to simply loop through all components of my doc for all of his configurations.

 

dmDoc = CType(docMgrApp.GetDocument(FilePath, dmDocType, True, dmOpenError), SwDMDocument15)
dmConfigMgr = dmDoc.ConfigurationManager
For Each configName As String In configNames
     dmConfig = dmConfigMgr.GetConfigurationByName(configName)
     dmComps = CType(dmConfig, SwDMConfiguration2).GetComponents
     For Each dmComp As SwDMComponent9 In CType(dmComps, Array)
          'Do something
     Next
Next

 

The line

dmComps = CType(dmConfig, SwDMConfiguration2).GetComponents

returns dmComps = Nothing. Upon further inspection, CType(dmConfig, SwDMConfiguration2) raises "InvalidCastException" (which is not caught by a Try Catch...). dmConfig is of type SwDMConfiguration. I have used this type of cast before without any problem. This portion of code actually worked at some point. I have no idea what happened. Any help will be greatly appreciated.

Outcomes