I can't help but see the interface differences you introduced:
You are trying to cast a SwDMConfiguration2 into a SwDMConfiguration, this will indeed not work.
Can you try to change either of those datatypes so they match? i suspect that that will work.
Thank you for your answer Gertjan. I am trying to cast a SwDMConfiguration into a SwDMConfiguration2 (not the opposite), which should be fine. See for example this API Help from Solidworks :
2018 SOLIDWORKS API Help - Get the Current Name of the Configuration of a Suppressed Component Example (VB.NET)
They use :
Dim config As SwDMConfiguration12
Dim configMgr As SwDMConfigurationMgr = dmDoc.ConfigurationManager
config = configMgr.GetConfigurationByName(configMgr.GetActiveConfigurationName())
Dim comps As Object = config.GetComponents()
Set the Embed Interop Types option on your document manager interop to False
Thank you Artem, I already tried and it didn't make any change. However this morning, after a complete rebuild of the solution, my .GetComponents works again... Mystery. Thanks guys for your help anyway.