473,407 Members | 2,629 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

ManagementObjectCollection.Count error

ManagementObjectCollection.Count is it rubbish or what?
I got one of the weirdest exception due to it:

COM object that has been separated from its underlying RCW can not be used.

Weird

--
"Life should NOT be a journey to the grave
with the intention of arriving safely in an
attractive and well preserved body,
but rather to skid in sideways,
chocolate in one hand, beer in the other,
body thoroughly used up,
totally worn out and screaming
WOO HOO what a ride!"
Nov 16 '05 #1
7 4765
What version of the framework are you running?
Is this a Windows Forms application?

Willy.

"Ian Frawley" <ch****@away.com> wrote in message
news:Od***************@news-1.opaltelecom.net...
ManagementObjectCollection.Count is it rubbish or what?
I got one of the weirdest exception due to it:

COM object that has been separated from its underlying RCW can not be
used.

Weird

--
"Life should NOT be a journey to the grave
with the intention of arriving safely in an
attractive and well preserved body,
but rather to skid in sideways,
chocolate in one hand, beer in the other,
body thoroughly used up,
totally worn out and screaming
WOO HOO what a ride!"

Nov 16 '05 #2
Hi Willy
version 1.1 and its a windows service.
Ian

"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:Ok**************@TK2MSFTNGP15.phx.gbl...
What version of the framework are you running?
Is this a Windows Forms application?

Willy.

"Ian Frawley" <ch****@away.com> wrote in message
news:Od***************@news-1.opaltelecom.net...
ManagementObjectCollection.Count is it rubbish or what?
I got one of the weirdest exception due to it:

COM object that has been separated from its underlying RCW can not be
used.

Weird

--
"Life should NOT be a journey to the grave
with the intention of arriving safely in an
attractive and well preserved body,
but rather to skid in sideways,
chocolate in one hand, beer in the other,
body thoroughly used up,
totally worn out and screaming
WOO HOO what a ride!"


Nov 16 '05 #3

"Willy Denoyette [MVP]" wrote in message

Lol is this how you earned your MVP?
What version of the framework are you running?
Is this a Windows Forms application?

Willy.

Nov 16 '05 #4
Ok, so this is the same issue as you posted before, right?
Could you post at least the complete function that executes the query
(including the query string) and a description how the method is called
(remote request, timer ...). Assuming you run this method on a separate
thread, did you explicitly initialize this one as an MTA thread?
Have you wrapped your ManagementObjectSearcher in a using[1] block? If you
didn't, and you don't use the variable holding the ManagementObjectSearcher
reference, there is a chance that the RCW is released when the finalizer
runs.

[1]
using(ManagementObjectSearcher mos = ....)
{

}
Willy.
"Ian Frawley" <ch****@away.com> wrote in message
news:WQ***************@news-1.opaltelecom.net...
Hi Willy
version 1.1 and its a windows service.
Ian

"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:Ok**************@TK2MSFTNGP15.phx.gbl...
What version of the framework are you running?
Is this a Windows Forms application?

Willy.

"Ian Frawley" <ch****@away.com> wrote in message
news:Od***************@news-1.opaltelecom.net...
> ManagementObjectCollection.Count is it rubbish or what?
> I got one of the weirdest exception due to it:
>
> COM object that has been separated from its underlying RCW can not be
> used.
>
> Weird
>
> --
> "Life should NOT be a journey to the grave
> with the intention of arriving safely in an
> attractive and well preserved body,
> but rather to skid in sideways,
> chocolate in one hand, beer in the other,
> body thoroughly used up,
> totally worn out and screaming
> WOO HOO what a ride!"
>
>



Nov 16 '05 #5
I am getting the same error. This appears to be a bug. My code is just a
Windows Form. The error does not occur on my XP Professional system, but
does on my Windows 2003 Server (includes 1.1). Here is the code:

Public Sub New(ByVal sComputerName As String)
If sComputerName = "(local)" Then
sComputerName = Environment.MachineName
End If

moScope = New ManagementScope("\\" + sComputerName + "\root\cimv2")

End Sub

Public Function RetrieveFixedDrives() As String()
Dim oSelectQuery As SelectQuery
Dim iDriveType As Integer
Dim sDrives(0) As String
Dim oSearcher As ManagementObjectSearcher
Dim oMgmtObjColl As ManagementObjectCollection
Dim oDisk As ManagementObject
Dim iCount As Integer
Try
oSelectQuery = New SelectQuery("win32_logicalDisk")

oSearcher = New ManagementObjectSearcher(moScope, oSelectQuery)
If oSearcher Is Nothing Then
Exit Function
End If

oMgmtObjColl = oSearcher.Get

'this "appears" to work and does not throw the exception
ReDim sDrives(oMgmtObjColl.Count)

iCount = 0

'Here is where it will fail
For Each oDisk In oMgmtObjColl

iDriveType =
Integer.Parse(oDisk.Properties("DriveType").Value. ToString)

If iDriveType = 3 Then
sDrives(iCount) =
oDisk.Properties("DeviceID").Value.ToString()

iCount += 1

End If
Next oDisk

Return sDrives
Catch ex As Exception
MsgBox(ex.Message.ToString & ": " & ex.InnerException.ToString &
": " & ex.StackTrace)
End Try
End Function

I fixed the issue by rewriting the code this way:

Public Sub New(ByVal sComputerName As String)
If sComputerName = "(local)" Then
sComputerName = Environment.MachineName
End If

moScope = New ManagementScope("\\" + sComputerName + "\root\cimv2")

End Sub

Public Function RetrieveFixedDrives() As String()
Dim oSelectQuery As SelectQuery
Dim iDriveType As Integer
Dim sDrives(0) As String
Dim oSearcher As ManagementObjectSearcher
Dim oMgmtObjColl As ManagementObjectCollection
Dim oDisk As ManagementObject
Dim iCount As Integer
Try
oSelectQuery = New SelectQuery("win32_logicalDisk")

oSearcher = New ManagementObjectSearcher(moScope, oSelectQuery)
If oSearcher Is Nothing Then
Exit Function
End If

iCount = 0

For Each oDisk In oSearcher.Get()

iDriveType =
Integer.Parse(oDisk.Properties("DriveType").Value. ToString)

If iDriveType = 3 Then
ReDim Preserve sDrives(iCount)
sDrives(iCount) =
oDisk.Properties("DeviceID").Value.ToString()

iCount += 1

End If
Next oDisk

Return sDrives
Catch ex As Exception
MsgBox(ex.Message.ToString & ": " & ex.InnerException.ToString &
": " & ex.StackTrace)
End Try
End Function
"Willy Denoyette [MVP]" wrote:
What version of the framework are you running?
Is this a Windows Forms application?

Willy.

"Ian Frawley" <ch****@away.com> wrote in message
news:Od***************@news-1.opaltelecom.net...
ManagementObjectCollection.Count is it rubbish or what?
I got one of the weirdest exception due to it:

COM object that has been separated from its underlying RCW can not be
used.

Weird

--
"Life should NOT be a journey to the grave
with the intention of arriving safely in an
attractive and well preserved body,
but rather to skid in sideways,
chocolate in one hand, beer in the other,
body thoroughly used up,
totally worn out and screaming
WOO HOO what a ride!"


Nov 16 '05 #6

"Bruce Parker" <bp********@nospam.nospam> wrote in message
news:07**********************************@microsof t.com...
I am getting the same error. This appears to be a bug. My code is just a
Windows Form. The error does not occur on my XP Professional system, but
does on my Windows 2003 Server (includes 1.1).


Works for me on W2K3 using Framework version 1.1.4322 (v1.1 SP1).

Willy
Nov 16 '05 #7
The system I am testing is a clean system with Framework version 1.1.4322.
It will fail every time. The other system it does work on has all the
development tools, office ... There is something else going on here,
especially if others like Ian is experiencing the exact same issue. I have
my work around, but I believe Microsoft needs to look into this further at
their labs.

"Willy Denoyette [MVP]" wrote:

"Bruce Parker" <bp********@nospam.nospam> wrote in message
news:07**********************************@microsof t.com...
I am getting the same error. This appears to be a bug. My code is just a
Windows Form. The error does not occur on my XP Professional system, but
does on my Windows 2003 Server (includes 1.1).


Works for me on W2K3 using Framework version 1.1.4322 (v1.1 SP1).

Willy

Nov 16 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Hari Om | last post by:
Here are the details of my error log files: I execute the command and get following message at console: ---------------------------------------------------------------------- ../sqlldr...
0
by: Fatt Shin | last post by:
Hi, I'm running MySQL 4.0.13, connecting from PowerBuilder 9 using ODCB Connector 3.51. I'm facing a problem where whenever I issue a SELECT COUNT(*) statement from PowerBuilder, I always get SQL...
5
by: Eric Johannsen | last post by:
I have a simple object that inherits from CollectionBase and overrides the Count property: namespace MyTest { public class CollTest : System.Collections.CollectionBase { public override int...
2
by: Alpha | last post by:
I have a window application. In one of the form, a datagrid has a dataview as its datasource. Initial filtering result would give the datavew 3 items. When I double click on the datagrid to edit...
68
by: Martin Joergensen | last post by:
Hi, I have some files which has the following content: 0 0 0 0 0 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 0 0 0 0 0
23
by: Gary Wessle | last post by:
Hi I have a vector<charwhich looks like this (a d d d a d s g e d d d d d k) I need to get the biggest count of consecutive 'd'. 5 in this example I am toying with this method but not sure if...
22
by: MP | last post by:
vb6,ado,mdb,win2k i pass the sql string to the .Execute method on the open connection to Table_Name(const) db table fwiw (the connection opened via class wrapper:) msConnString = "Data Source="...
3
by: Auddog | last post by:
I have the following query that works in mysql: select id, order_no, price, count(item_no), sum(price) from production WHERE item_no = '27714' group by item_no; When I setup my query in php,...
26
by: Ping | last post by:
Hi, I'm wondering if it is useful to extend the count() method of a list to accept a callable object? What it does should be quite intuitive: count the number of items that the callable returns...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.