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

  • Thread starter Thread starter moondaddy
  • Start date Start date
M

moondaddy

I have a smartclient app in vb.net 1.1. In the app's startup form's
form_load event I have some code that gets the machine's MAC address which I
think is the culprit here. The code runs fine on my dev machine and as far
as I know it runs OK on the client machines it gets installed on. I now
have a test machine which is a brand new dell with WinXP sp2 and ALL windows
updates (including the .net framework 1.1 and all relate SPs and updates,
but not .net 2.0). I have not installed MS Office or any other apps on it
so it is a very clean machine. my smart client app installs OK on the test
machine, but when it starts up I get the following Error:

<<<
System.Management.ManagementException: COM object that has been separated
from its underlying RCW can not be used.

System.Runtime.InteropServices.InvalidComObjectException: COM object that
has been separated from its underlying RCW can not be used. at
system.Management.IEnumWbemClassObject.Clone_(IEnumWbemClassObject&amp;
ppEnum) at system.Management.ManagementObjectCollection.GetEnumerator()
and here's the code where I think the problem is, however, I'm not getting
the exact line of code in the exception:

Dim mc As System.Management.ManagementClass
Dim mo As System.Management.ManagementObject
mc = New
System.Management.ManagementClass("Win32_NetworkAdapterConfiguration")
Dim moc As System.Management.ManagementObjectCollection = mc.GetInstances()
Dim found As Boolean
For Each mo In moc
If CType(mo.Item("IPEnabled"), Boolean) = True Then
If mo.Item("MacAddress").ToString() = "bla bla bla" Then
found = True
Exit For
End If
End If
Next


Can anyone tell me why I would get this error on a clean machine? And how
should I write this correctly to avoid this error?
 
Hi

I think you may try to run the code in a local .NET application on the
"problem" machine to see if that works.
Because the management class depends on the WMI on the machine, we need to
test to see if that works fine.
If that works, I think you may try to check the .NET security setting.
Becauses by default an application from network (e.g. a smart client) is
not full trusted, but to query the wmi(management class), we need somewhat
high permission.
I think you may try to check the CAS setting to make sure the smartclient
URL path is full tusted.

Here is a link about the tool that will set the CAS for the machine.
Configuring Security Policy Using the Code Access Security Policy Tool
(Caspol.exe)
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpconUsingCodeAccessSecurityPolicyToolCaspolexe.asp

.NET Framework Configuration Tool (Mscorcfg.msc)
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cptools/htm
l/cpconNETFrameworkAdministrationToolMscorcfgmsc.asp

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top