Note that there are some explanatory texts on larger screens.

plurals
  1. POVirtual Server IIS WMI Problem
    text
    copied!<p>I have been tasked with finding out what is causing an issue with this bit of code:</p> <pre><code>public static ArrayList GetEthernetMacAddresses() { ArrayList addresses = new ArrayList(); ManagementClass mc = new ManagementClass("Win32_NetworkAdapter"); // This causes GetInstances(options) // to return all subclasses of Win32_NetworkAdapter EnumerationOptions options = new EnumerationOptions(); options.EnumerateDeep = true; foreach (ManagementObject mo in mc.GetInstances(options)) { string macAddr = mo["MACAddress"] as string; string adapterType = mo["AdapterType"] as string; if (!StringUtil.IsBlank(macAddr) &amp;&amp; !StringUtil.IsBlank(adapterType)) { if (adapterType.StartsWith("Ethernet")) { addresses.Add(macAddr); } } } return addresses; } </code></pre> <p>On our (Win2003) virtual servers, this works when run as part of a console application but not from a web service running on IIS (on that same machine).</p> <p>Alternatively, I can use this code in a web service on IIS (on the virtual server) and get the correct return values:</p> <pre><code>public static string GetMacAddresses() { ManagementClass mgmt = new ManagementClass( "Win32_NetworkAdapterConfiguration" ); ManagementObjectCollection objCol = mgmt.GetInstances(); foreach (ManagementObject obj in objCol) { if ((bool)obj["IPEnabled"]) { if (sb.Length &gt; 0) { sb.Append(";"); } sb.Append(obj["MacAddress"].ToString()); } obj.Dispose(); } } </code></pre> <p>Why does the second one work and not the first one?</p> <p>Why only when called through an IIS web service on a virtual machine?</p> <p>Any help would be appreciated.</p> <hr> <p><strong>UPDATE:</strong> After much telephone time with all different levels of MS Support, the've come to the conclusion that this is "As Designed".</p> <p>Since it is on a driver level for the virtual network adapter driver, the answer was that we should change our code "to work around the issue".</p> <p>This means that you cannot reliable test code on virtual servers unless you with the same code that you use on physical servers, since we can't guarantee that the servers are exact replicas...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload