Registered VirtualMachine enumeration fails

Mar 17, 2010 at 12:21 PM


My application is crashing randomly when I enumerate all registered machines :


foreach (VMWareVirtualMachine vm in VirtualHost.RegisteredVirtualMachines)
if (vm.PathName.Contains(VM_Path))
VMWareVirtualMachine virtualMachine = virtualHost.Open(vm.PathName);

VMWareSnapshot snapshot = virtualMachine.Snapshots.GetNamedSnapshot("Installation");

if (snapshot.DisplayName == "Installation")


Randomly because, it works and suddenly, it stops working.
Vix.dll is responsible for the crash according to the event viewer : faulting module vix.dll, version

Any idea what's wrong?

Mar 17, 2010 at 2:33 PM

You need to dispose of the virtualMachine and the snapshot objects. VixCOM keeps references to all opened objects and they point nowhere when garbage collection kicks in. It's the joys of mixing managed, unmanaged code and COM.

using(VMWareVirtualMachine virtualMachine = virtualHost.Open(vm.PathName))

same with the snapshot and anything else that implements IDisposable in VMWareTasks.

Mar 18, 2010 at 10:24 AM

Thank you dblock for your quick answer and for all the work you have done on this project :)

My application is now much more stable!