ManagementException - 无效类ManagementException

由网友(Ganme丶柠檬)分享简介:我有一个问题,查询WMI,有我完全莫名其妙。该应用程序我建立利用已安装的VMware View的代理的一部分到VDI桌面WMI计数器。该计数器提供有关远程显示协议PCoIP的信息。I am having an issue querying WMI that has me completely baffled. The...

我有一个问题,查询WMI,有我完全莫名其妙。该应用程序我建立利用已安装的VMware View的代理的一部分到VDI桌面WMI计数器。该计数器提供有关远程显示协议PCoIP的信息。

I am having an issue querying WMI that has me completely baffled. The Application I am building utilizes WMI counters that are installed as part of the VMware View Agent into a VDI desktop. The counters provide information about the remote display protocol PCoIP.

我有工作code查询柜台:

I have working code to query the counters:

ManagementObjectSearcher searcher = new ManagementObjectSearcher();

ObjectQuery generalQuery = new ObjectQuery("SELECT * FROM Win32_PerfRawData_TeradiciPerf_PCoIPSessionGeneralStatistics");

// Many other queries...

searcher.Query = generalQuery;
foreach (ManagementObject obj in searcher.Get())
{
  // Total session duration
  ulong sessionDurationSec = Convert.ToUInt64(obj["SessionDurationSeconds"]);
  // Get other items...
}

这code是从现有的,工作的.NET 3.5应用程序。我现在已经创建了一个新的.NET 4.0应用程序,我使用的是完全相同的code - 它失败每次与无效类ManagementException

This code is from an existing, working .NET 3.5 application. I have now created a new .NET 4.0 application, and I am using the exact same code - which fails every time with an "Invalid Class" ManagementException.

我已经验证应用程序的权限是正确的,我还新的.NET 4.0应用程序尝试查询其他项目,如Win32_Process的和它的作品没有问题。

I have verified application permissions are correct, I have also tried querying other items like "Win32_Process" in the new .NET 4.0 application and it works without issue.

在令人费解的是,在计数器出现,做工精细的性能监视器和WMIC:

The puzzling thing is, the counters appear and work fine in perfmon and wmic:

http://hirstius.com/media/stackoverflow/perfmon.png

不过,从内部WMI CIM Studio或WMI code的创造者 - 什么:

But from within WMI CIM Studio, or WMI Code Creator - nothing:

http://hirstius.com/media/stackoverflow/WMI_$c$ c_creator.png

在各方面我能想到的应用程序都是一样的 - 相同权限的诠释,他app.manifest,以同样的方式被调用完全相同的code(通过定时器)。唯一的区别是.NET 3.5 VS 4.0 - 但很显然的计数器的是的出现为多个应用程序可以看到它们,但同等数量不能

In every way I can think of the applications are the same - same permissions int he app.manifest, exact same code being invoked in the same way (via a Timer). The only difference is the .NET 3.5 vs 4.0 - but it's clear the counters are there as more than one application can see them, yet an equal number cannot.

有谁知道的.NET 3.5和4.0的任何可能的差异,将导致此?或者为什么,可能的话,计数器将是可见的某些应用程序,而不是别人?有一些环境设置我失踪所需的.NET 4.0?目前,我不知道哪里去这个进一步解决。

Does anyone know of any possible difference between .NET 3.5 and 4.0 that would cause this? Or why, possibly, the counters would be visible to certain application and not others? Is there some environmental setting I am missing that is required for .NET 4.0? Currently I do not know where to go to troubleshoot this further.

推荐答案

在由汉斯帕桑特在这个问题的答案是:

As stated in the comments by Hans Passant the answer to this question is:

从86更改EXE项目的平台目标设置值为anycpu

change the EXE project's platform target setting from x86 to AnyCPU

其由OP证实:

我想这意味着计数器仅64位?这也可以解释为什么某些应用程序可能会或可能不会看到他们 - 基于哪个平台,他们针对

I would guess that means the counters are 64bit only? It would also explain why certain apps could or could not see them - based upon which platform they were targeted for.

阅读全文

相关推荐

最新文章