Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Strange (sorry that is the best title I could come up wi
Message
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00997385
Message ID:
00997741
Views:
13
I have found what the problem was. The problem was that I didn't post exactly the same code as the code I was trying to run. The code I tried to run had an extra messagebox statement:
System.Management.ManagementObjectCollection UserSearch = new System.Management.ManagementObjectSearcher("Select * FROM Win32_Account").Get();
			
MessageBox.Show("Count:"+UserSearch.Count.ToString()); // removing this line will noth throw an exception in the foreach

foreach(System.Management.ManagementObject mo in UserSearch)
{
	if (MessageBox.Show(mo["Name"].ToString(),"next?",MessageBoxButtons.YesNo) == DialogResult.No)
	{
		break;
	}	
}
The exception that is thrown in the foreach has the following message:
An unhandled exception of type 'System.Management.ManagementException' occurred in system.management.dll
Additional information: COM object that has been separated from its underlying RCW can not be used.
I am unsure why the messagebox causes problems.

Could you guys please try to run the code above whith and without the messagebox before the foreach loop just to verify that I am not seeing things?

Any explanation offered for this would also be appreciated.

Thanks,
Einar


>Here is some strange code. button11_Click throws an exception in the foreach body. They both look like apples to me :)
>
>
>private void button11_Click(object sender, System.EventArgs e)
>{
>	ManagementObjectCollection UserSearch = new ManagementObjectSearcher("Select * FROM Win32_Account").Get();
>	foreach(ManagementObject mo in UserSearch)
>	{
>		MessageBox.Show(mo["Name"].ToString());	
>	}
>}
>
>private void button12_Click(object sender, System.EventArgs e)
>{
>	System.Management.ManagementObjectSearcher searcher = new System.Management.ManagementObjectSearcher("SELECT * FROM Win32_Account");
>	foreach (System.Management.ManagementObject mo in searcher.Get())
>	{
>		MessageBox.Show(mo["Name"].ToString());
>	}
>}
>
>
>Is there something I am missing? Why will one work and not the other one?
>It is not a big deal but it is driving me crazy.
>
>Einar
Semper ubi sub ubi.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform