vCheck-vSphere icon indicating copy to clipboard operation
vCheck-vSphere copied to clipboard

Get-View EventManager Function Fails With Error Object of type 'System.Xml.XmlNode[]' cannot be converted to type 'VMware.Vim.Event'

Open MasterChiefJon opened this issue 7 years ago • 15 comments

We recently upgraded our vCenter from v6.0 to v6.5. Since then, I noticed that the Connection plugin is failing at line 299 with the following error:

Get-View : 3/8/2018 8:48:28 AM  Get-View                Object of type 'System.Xml.XmlNode[]' cannot be converted to type
'VMware.Vim.Event'.
At C:\Users\AdcockJ\Documents\Scripts\PowerCLI\vCheck-6.24-Test\Plugins\00 Initialize\00 Connection Plugin for
vCenter.ps1:299 char:19
+       $eventMgr = Get-View EventManager
+                   ~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-View], VimException
    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.DotNetInterop.
   GetVIView

Do I need to change something in my Connection plugin that is unique to vCenter v6.5?

MasterChiefJon avatar Mar 08 '18 14:03 MasterChiefJon

I need to add that this may also be related to my new vCheck machine. I used to run vCheck using PowerCLI v5.5 and now I'm running vCheck in PowerCLI v6.5 Release 1.

MasterChiefJon avatar Mar 08 '18 14:03 MasterChiefJon

OK, I have run this a bunch of times, and I am no longer getting the same error. Now I am seeing this instead. And it's repeating 68 times.

Exception calling "ReadNextEvents" with "1" argument(s): "Error in deserializing body of reply message for operation
'ReadNextEvents'."
At C:\Users\AdcockJ\Documents\Scripts\PowerCLI\vCheck-6.24-Test\Plugins\00 Initialize\00 Connection Plugin for
vCenter.ps1:340 char:13
+             $eventsBuffer = $eventCollector.ReadNextEvents($eventnumb ...
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : CommunicationException

MasterChiefJon avatar Mar 08 '18 18:03 MasterChiefJon

Same here

mimmus avatar May 24 '18 13:05 mimmus

I'm successfully executing the same vCheck code (version 6.25) against four vCenter 6.0 servers (Windows) and four vCenter 6.5 servers. Per VMware Product Interoperability Matrices, PowerCLI 6.5.1 doesn't support vCenter 6.5 U1 and newer.

My environment for reference:

PS > Get-Module -list -Name VMware.PowerCLI | Select-Object Name, Version

Name            Version
----            -------
VMware.PowerCLI 10.0.0.7895300
PS > $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.14409.1012
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14409.1012
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

gregharms avatar May 24 '18 21:05 gregharms

I was still at Powershell 4.0 and PowerCLI 6.5! Now same versions as you but still errors.

mimmus avatar May 25 '18 08:05 mimmus

I upgraded to PowerCLI v10.1.0. Same 'ReadNextEvents' error.

Name            Version
----            -------
VMware.PowerCLI 10.1.0.8403314
Name                           Value
----                           -----
PSVersion                      5.1.16299.431
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.16299.431
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1`

MasterChiefJon avatar May 25 '18 12:05 MasterChiefJon

Looks like both your originating error and the current error reside in the calls to the Get-VIEventPlus function, according to the line numbers in the error. In the 00 Connection Plugin for vCenter plugin, it's called from two other functions - Get-VMLastPoweredOffDate and Get-VMLastPoweredOnDate. Both of those functions feed a virtual machine object to Get-VIEventPlus. Perhaps there's a VM in the inventory that has unexpected values/characters in the object contents or events?

If it were me, I'd run vCheck with the Verbose parameter to see if that would tell me which VM it's working on before crashing out.

gregharms avatar May 25 '18 13:05 gregharms

Errors start almost immediately:

Begin Plugin Processing
[16:21:30] ..start calculating Connection settings for vCenter by Alan Renouf v1
.20 [1 of 109]
[16:22:05] ..finished calculating Connection settings for vCenter by Alan Renouf
 v1.20 [1 of 109]
[16:22:05] ..start calculating General Information by Alan Renouf, Frederic Mart
in v1.3 [2 of 109]
Exception calling "ReadNextEvents" with "1" argument(s): "Error in
deserializing body of reply message for operation 'ReadNextEvents'."
At C:\Scripts\vCheck-vSphere\Plugins\00 Initialize\00 Connection Plugin for
vCenter.ps1:340 char:13
+             $eventsBuffer = $eventCollector.ReadNextEvents($eventnumb ...
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : CommunicationException

Section involved is this:

331:      if(!$Entity){
332:         $Entity = @(Get-Folder -NoRecursion)
333:      }
334:      $entity | Foreach-Object {
335:         $eventFilter.entity.entity = $_.ExtensionData.MoRef
336:         $eventCollector = Get-View ($eventMgr.CreateCollectorForEvents($eventFilter))
337:         $eventsBuffer = $eventCollector.ReadNextEvents($eventnumber)
338:         while($eventsBuffer){
339:            $events += $eventsBuffer
340:            $eventsBuffer = $eventCollector.ReadNextEvents($eventnumber)
341:         }

mimmus avatar May 25 '18 14:05 mimmus

In response to GregHarms recommendation, I ran my job with the -Verbose switch. It showed no additional information (so perhaps I put the switch in the wrong location?): C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command "& {C:\Users\<username>\Documents\Scripts\PowerCLI\vCheck-6.24\vCheck.ps1}" -Verbose

MasterChiefJon avatar May 25 '18 18:05 MasterChiefJon

Some talk about this being a bug in the 6.5 API - https://communities.vmware.com/message/2764714#2764714 - with talk about downgrading to PowerCLI 6.3 (to force 6.0 API connection) or exclude certain events from processing. :(

gregharms avatar May 29 '18 03:05 gregharms

After "git cloning" again the whole repo, I'm having much less issues then before, probably related only to 1-3 VMs. I noticed that after editing a few files with my editor, format changes from "UNIX/ANSI" to "PC/UNICODE" and I get LOTS OF ERRORS!

mimmus avatar May 29 '18 08:05 mimmus

Hi thread. From the same server, I run vCheck against 2 vCenters (both running 6.5.0 build 8024368), and only one of them gives me this error. How does that make sense?

*edit: this was using PowerCLI 6.5 I've downgraded to PowerCLI 6.3 R1, and it appears to now run clean for both target vCenters.

Alfaj0r avatar Nov 09 '18 21:11 Alfaj0r

Probably it is related to the presence of certain events

mimmus avatar Nov 12 '18 09:11 mimmus

Should be fixed in PowerCLI 11.3.0. Please confirm, otherwise, I propose to close this issue.

lucdekens avatar Nov 14 '19 20:11 lucdekens

See also #637

lucdekens avatar Nov 14 '19 20:11 lucdekens