Hi, i have developed a web-based project to call perfmon data using WMI query. During debug in Windows 7, VS 2010, it works fine. But, when i moved to Windwos Server 2008 with IIS 7.0, the problem came. Some of WMI query can be executed, like the Thread
Count, Handles Count or Drive Usage. But the other some queries obtained error.
Eg, It appaers the error when excecute to this part
The code that u proposed just to get the exception too... But my problem is the object of WMI query executed cannot go to an instance. I don't know whether the WMI query can be executed in IIS 7.0 or not, if it can, why do the object cannot be retrived??
i try to close the "catch" and get the details. The details are as shown:
Server Error in '/WebSite4(2)' Application.
--------------------------------------------------------------------------------
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
_Default.Detection(String a, DataTable dt) +317
_Default.Button1_Click(Object sender, EventArgs e) +1119
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +153
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3690
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1
Oh, God ... looks like when i run it in the DefaultApplicationPool using ApplicationPoolIdentity in the remote server in IIS, it cause the error...
When, i switch to LocalSystem or Network Service, it works... Still don know why causing this.
Questions:
1) Why it can be run in LocalSystem or Network Service but not in the ApplicationPoolIdentity
2) Anything should i use if i want the WMI query to be executed in the intranet with over 200 servers??
Thanks, almost done... (Haiz, troubling me for a whole day before i try to switch AppPool Porperty)....
GargoyleXxX
Member
2 Points
17 Posts
How to fix "object reference not set to an instance of an object"
May 28, 2012 04:16 AM|LINK
Hi, i have developed a web-based project to call perfmon data using WMI query. During debug in Windows 7, VS 2010, it works fine. But, when i moved to Windwos Server 2008 with IIS 7.0, the problem came. Some of WMI query can be executed, like the Thread Count, Handles Count or Drive Usage. But the other some queries obtained error.
Eg, It appaers the error when excecute to this part
try { string query = "SELECT * FROM Win32_Processor"; ObjectQuery objectQuery = new ObjectQuery(query); ManagementObjectSearcher searcher = new ManagementObjectSearcher(objectQuery); foreach (ManagementObject productInfo in searcher.Get()) { string processorUsed = productInfo["LoadPercentage"].ToString(); drow[CUsage] = processorUsed; Session["CPU#"] = productInfo["NumberOfCores"].ToString(); } } catch (Exception ex) { ShowMessageBox("Processor Usage" + ex.Message); }I am still new to ASP.net and IIS. Any suggestion for this??
pradeepnt
Member
266 Points
154 Posts
Re: How to fix "object reference not set to an instance of an object"
May 28, 2012 05:13 AM|LINK
hi.....
you can use
catch (NullReferenceException ex) { ShowMessageBox("Processor Usage" + ex.Message); }Pradeep Narayan
GargoyleXxX
Member
2 Points
17 Posts
Re: How to fix "object reference not set to an instance of an object"
May 28, 2012 06:02 AM|LINK
The code that u proposed just to get the exception too... But my problem is the object of WMI query executed cannot go to an instance. I don't know whether the WMI query can be executed in IIS 7.0 or not, if it can, why do the object cannot be retrived?? i try to close the "catch" and get the details. The details are as shown:
but, i still cant get where is the wrong part....
GargoyleXxX
Member
2 Points
17 Posts
Re: How to fix "object reference not set to an instance of an object"
May 29, 2012 04:01 AM|LINK
Oh, God ... looks like when i run it in the DefaultApplicationPool using ApplicationPoolIdentity in the remote server in IIS, it cause the error...
When, i switch to LocalSystem or Network Service, it works... Still don know why causing this.
Questions:
1) Why it can be run in LocalSystem or Network Service but not in the ApplicationPoolIdentity
2) Anything should i use if i want the WMI query to be executed in the intranet with over 200 servers??
Thanks, almost done... (Haiz, troubling me for a whole day before i try to switch AppPool Porperty)....