Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 149519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:08:37+00:00 2026-05-11T09:08:37+00:00

I have been tasked with finding out what is causing an issue with this

  • 0

I have been tasked with finding out what is causing an issue with this bit of 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) && !StringUtil.IsBlank(adapterType))         {             if (adapterType.StartsWith('Ethernet')) {                 addresses.Add(macAddr);                   }         }         }     return addresses; } 

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).

Alternatively, I can use this code in a web service on IIS (on the virtual server) and get the correct return values:

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 > 0)             {                 sb.Append(';');             }             sb.Append(obj['MacAddress'].ToString());         }         obj.Dispose();     } } 

Why does the second one work and not the first one?

Why only when called through an IIS web service on a virtual machine?

Any help would be appreciated.


UPDATE: After much telephone time with all different levels of MS Support, the’ve come to the conclusion that this is ‘As Designed’.

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’.

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…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T09:08:38+00:00Added an answer on May 11, 2026 at 9:08 am

    Okay, so I wrote this code to test the issue:

    public void GetWin32_NetworkAdapter() {     DataTable dt = new DataTable();     dt.Columns.Add('AdapterName', typeof(string));     dt.Columns.Add('ServiceName', typeof(string));     dt.Columns.Add('AdapterType', typeof(string));     dt.Columns.Add('IPEnabled', typeof(bool));     dt.Columns.Add('MacAddress', typeof(string));      //Try getting it by Win32_NetworkAdapterConfiguration       ManagementClass mgmt = new ManagementClass('Win32_NetworkAdapter');     EnumerationOptions options = new EnumerationOptions();     options.EnumerateDeep = true;      ManagementObjectCollection objCol = mgmt.GetInstances(options);      foreach (ManagementObject obj in objCol)     {         DataRow dr = dt.NewRow();         dr['AdapterName'] = obj['Caption'].ToString();         dr['ServiceName'] = obj['ServiceName'].ToString();         dr['AdapterType'] = obj['AdapterType'];         dr['IPEnabled'] = (bool)obj['IPEnabled'];         if (obj['MacAddress'] != null)         {             dr['MacAddress'] = obj['MacAddress'].ToString();         }         else         {             dr['MacAddress'] = 'none';         }         dt.Rows.Add(dr);     }      gvConfig.DataSource = dt;     gvConfig.DataBind();  } 

    When it’s run on a physical IIS box I get this: Physical IIS server http://img14.imageshack.us/img14/8098/physicaloutput.gif

    Same code on Virtual IIS server: Virtual server http://img25.imageshack.us/img25/4391/virtualoutput.gif

    See a difference? It’s on the first line. The virtual server doesn’t return the ‘AdapterType’ string. Which is why the original code was failing.

    This brings up an interesting thought. If Virtual Server is supposed to be an ‘virtual’ representation of a real IIS server, why doesn’t it return the same values?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 89k
  • Answers 90k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer There is not just third option, there are many :)… May 11, 2026 at 5:59 pm
  • Editorial Team
    Editorial Team added an answer If the amount of data is not ridiculously large, use… May 11, 2026 at 5:59 pm
  • Editorial Team
    Editorial Team added an answer FYI, Using unescaped in any JavaScript script causes this issue… May 11, 2026 at 5:59 pm

Related Questions

Alright I know this isn't 100% related to programming (the Excel book in question
I have been tasked with finding an open source DOM XML parser. The parser
I have been tasked with implementing a PKI library in C# for a company
I have been tasked with going through a number of ColdFusion sites that have

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.