IMachine::deleteConfig(IMachine::unregister()) not working

Discussion about using the VirtualBox API, Tutorials, Samples.
Post Reply
SmithersTheOracle
Posts: 60
Joined: 28. Dec 2019, 08:58
Primary OS: MS Windows 7
VBox Version: PUEL
Guest OSses: Windows, Linux

IMachine::deleteConfig(IMachine::unregister()) not working

Post by SmithersTheOracle »

I'm working with the VirtualBox Windows COM object to try to delete a test VM. IMachine::deleteConfig() is throwing an exception when I run it.

Code: Select all

PS C:\> $vbox = New-Object -ComObject VirtualBox.VirtualBox
PS C:\> $vbox.Machines[6].Name
OtherTest64
PS C:\> $vbox.Machines[6].Unregister.OverloadDefinitions
SAFEARRAY(IMedium) Unregister (CleanupMode)
PS C:\> $vbox.Machines[6].DeleteConfig.OverloadDefinitions
IProgress DeleteConfig (SAFEARRAY(IMedium))
PS C:\> $vbox.Machines[6].DeleteConfig($vbox.Machines[6].Unregister(3))
Exception setting "DeleteConfig": Cannot convert the "System.Object[]" value of type "Object[]" to type "array".
At line:1 char:1
+ $vbox.Machines[6].DeleteConfig($vbox.Machines[6].Unregister(3))
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : RuntimeException
As you can see, Unregister() says it returns the IMedium SafeArray needed for DeleteConfig(), but DeleteConfig() is saying that it's receiving a System.Object[] from Unregister(). I can't get more direct than that. There aren't any PowerShell variables or anything which might be getting in the way.

I thought that maybe it was because the returned array was Null, so I attached 2 test disks to the test VM before running this. It unregisters the VM, but it won't delete the config or the disks.

Oddly, this whole process works fine if I run it from the web service. Does anyone have any idea what's wrong here?
Post Reply