VMware {code} Community
rkt
Contributor
Contributor
Jump to solution

VMware Server 2.0, VIX API 1.2, MS VS2005 Visual Basic ==> DISP_E_TYPEMISMATCH

Hi!

I tried to run that code:

-


Private Sub Connect(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Connect.Click

Dim libr

Dim host

Dim vm

Dim err

Dim results

Dim job

libr = CreateObject("VixCOM.VixLib")

job = libr.Connect(VixCOM.Constants.VIX_API_VERSION, VixCOM.Constants.VIX_SERVICEPROVIDER_VMWARE_VI_SERVER, "https://localhost:8333/sdk", 0, "user", "pw", 0, Nothing, Nothing)

' results needs to be initialized before it's used, even if it's just going to be overwritten.

results = Nothing

err = job.Wait((VixCOM.Constants.VIX_PROPERTY_JOB_RESULT_HANDLE), results)

If libr.ErrorIndicatesFailure(err) Then

' Handle the error...

End If

host = results(0)

job = host.OpenVM("C:\VMs\winxppro\winxppro.vmx", Nothing)

err = job.Wait((VixCOM.Constants.VIX_PROPERTY_JOB_RESULT_HANDLE), results)

If libr.ErrorIndicatesFailure(err) Then

' Handle the error...

End If

vm = results(0)

job = vm.PowerOn(VixCOM.Constants.VIX_VMPOWEROP_LAUNCH_GUI, Nothing, Nothing)

err = job.WaitWithoutResults()

If libr.ErrorIndicatesFailure(err) Then

' Handle the error...

End If

End Sub

-


Like you can see, I modified an example of the VIX reference guide. For running it, I added a reference to the VixCOM 1.0 Type Library (VixCOM.dll).

My problem is that I get always this error in the line of "libr.Connect(...)":

"An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in Microsoft.VisualBasic.dll

Additional information: Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))"

Is anybody able to help me? Thanks!

The Output of the IDE:

'vixPowerOn.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll', No symbols loaded.

'vixPowerOn.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities\8.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.dll', No symbols loaded.

'vixPowerOn.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\System.Windows.Forms\2.0.0.0__b77a5c561934e089\System.Windows.Forms.dll', No symbols loaded.

'vixPowerOn.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll', No symbols loaded.

'vixPowerOn.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\System.Drawing\2.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll', No symbols loaded.

'vixPowerOn.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities.Sync\8.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.Sync.dll', No symbols loaded.

'vixPowerOn.vshost.exe' (Managed): Loaded 'C:\Documents and Settings\user\My Documents\Visual Studio 2005\Projects\vixPowerOn\vixPowerOn\bin\Debug\vixPowerOn.vshost.exe', No symbols loaded.

'vixPowerOn.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_32\System.Data\2.0.0.0__b77a5c561934e089\System.Data.dll', No symbols loaded.

'vixPowerOn.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\System.Deployment\2.0.0.0__b03f5f7f11d50a3a\System.Deployment.dll', No symbols loaded.

'vixPowerOn.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\System.Xml\2.0.0.0__b77a5c561934e089\System.Xml.dll', No symbols loaded.

'vixPowerOn.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\Microsoft.VisualBasic\8.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualBasic.dll', No symbols loaded.

The thread 0xa10 has exited with code 0 (0x0).

The thread 0xb38 has exited with code 0 (0x0).

'vixPowerOn.vshost.exe' (Managed): Loaded 'C:\Documents and Settings\user\My Documents\Visual Studio 2005\Projects\vixPowerOn\vixPowerOn\bin\Debug\vixPowerOn.exe', Symbols loaded.

'vixPowerOn.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\System.Runtime.Remoting\2.0.0.0__b77a5c561934e089\System.Runtime.Remoting.dll', No symbols loaded.

A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll

A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in Microsoft.VisualBasic.dll

An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in Microsoft.VisualBasic.dll

Additional information: Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))

The thread 0xa68 has exited with code 0 (0x0).

The program '[4048] vixPowerOn.vshost.exe: Managed' has exited with code -532459699 (0xe0434f4d).

0 Kudos
1 Solution

Accepted Solutions
admin
Immortal
Immortal
Jump to solution

The sample code given is for VBScript, which is a little different VB.NET, unfortunately.

You'll need to change to code to something like this:

Private Sub Connect(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Connect.Click
Dim libr As VixCOM.VixLib
Dim host As VixCOM.IHost
Dim job As VixCOM.IJob
Dim vm As VixCOM.IVM
Dim results = Nothing
Dim err

libr = New VixCOM.VixLib()
job = libr.Connect(VixCOM.Constants.VIX_API_VERSION, VixCOM.Constants.VIX_SERVICEPROVIDER_VMWARE_VI_SERVER, "https://localhost:8333/sdk", 0, "user", "pw", 0, Nothing, Nothing)
host = Nothing
Dim propertyIDs() As Integer = {VixCOM.Constants.VIX_PROPERTY_JOB_RESULT_HANDLE}
Dim err = job.Wait(propertyIDs, results)
If libr.ErrorIndicatesFailure(err) Then
   ' Handle the error...
End If
host = results(0)


job = host.OpenVM("C:\vms\winxppro\winxppro.vmx", Nothing)
err = job.Wait(propertyIDs, results)
If libr.ErrorIndicatesFailure(err) Then
   ' Handle the error...
End If
vm = results(0)

job = vm.PowerOn(VixCOM.Constants.VIX_VMPOWEROP_LAUNCH_GUI, Nothing, Nothing)
err = job.WaitWithoutResults()
If libr.ErrorIndicatesFailure(err) Then
   ' Handle the error...
End If
End Sub

View solution in original post

0 Kudos
2 Replies
admin
Immortal
Immortal
Jump to solution

The sample code given is for VBScript, which is a little different VB.NET, unfortunately.

You'll need to change to code to something like this:

Private Sub Connect(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Connect.Click
Dim libr As VixCOM.VixLib
Dim host As VixCOM.IHost
Dim job As VixCOM.IJob
Dim vm As VixCOM.IVM
Dim results = Nothing
Dim err

libr = New VixCOM.VixLib()
job = libr.Connect(VixCOM.Constants.VIX_API_VERSION, VixCOM.Constants.VIX_SERVICEPROVIDER_VMWARE_VI_SERVER, "https://localhost:8333/sdk", 0, "user", "pw", 0, Nothing, Nothing)
host = Nothing
Dim propertyIDs() As Integer = {VixCOM.Constants.VIX_PROPERTY_JOB_RESULT_HANDLE}
Dim err = job.Wait(propertyIDs, results)
If libr.ErrorIndicatesFailure(err) Then
   ' Handle the error...
End If
host = results(0)


job = host.OpenVM("C:\vms\winxppro\winxppro.vmx", Nothing)
err = job.Wait(propertyIDs, results)
If libr.ErrorIndicatesFailure(err) Then
   ' Handle the error...
End If
vm = results(0)

job = vm.PowerOn(VixCOM.Constants.VIX_VMPOWEROP_LAUNCH_GUI, Nothing, Nothing)
err = job.WaitWithoutResults()
If libr.ErrorIndicatesFailure(err) Then
   ' Handle the error...
End If
End Sub

0 Kudos
esloof
Expert
Expert
Jump to solution

vm = results(0)

Results is error:

Unable to cast COM object of type 'System.__ComObject' to interface type 'VixCOM.IVM'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{11E879B1-7969-4654-BE4B-3F05679F742E}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

Update: I fixed it, there was a typo in my VMX path

Look at this : Online Training – Automating vSphere with the VIX API http://www.ntpro.nl/blog/archives/1483-Online-Training-Automating-vSphere-with-the-VIX-API.html

Cool huh Smiley Happy

0 Kudos