C# Assembly Reference issue ??

Last post 05-08-2008 4:39 PM by che3358. 4 replies.

Sort Posts:

  • C# Assembly Reference issue ??

    05-08-2008, 11:44 AM
    • Loading...
    • NemesisMtl
    • Joined on 05-08-2008, 3:38 PM
    • Posts 2

    Hi,

     

    I'm kind of new to .Net coding and I'm trying to write a script that will output to a webpage the MAC Address of the computer accessing this page, and I keep getting that compilation error here's the error


     Compiler Error Message: CS0234: The type or namespace name 'Management' does not exist in the namespace 'System' (are you missing an assembly reference?)

     

    here's my cs code:

     

    1    using System;
    2    using System.Text;
    3    using System.Runtime.InteropServices;
    4    using System.Management;
    5    
    6      public class GetInfo
    7        {
    8    
    9            public string GetMACAddress()
    10               {
    11               ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
    12               ManagementObjectCollection moc = mc.GetInstances();
    13               string MACAddress=String.Empty;
    14               foreach(ManagementObject mo in moc)
    15               {
    16                   if(MACAddress==String.Empty)  // only return MAC Address from first card
    17                   {
    18                       if((bool)mo["IPEnabled"] == true) MACAddress= mo["MacAddress"].ToString() ;
    19                   }
    20                           mo.Dispose();
    21               }
    22               MACAddress=MACAddress.Replace(":","");
    23               return MACAddress;
    24               }
    25       }
    26   
    

      

    and here's aspx page code:

     

     
    <%@ page Language="C#" Inherits="GetInfo" src="macaddress.cs" %>
    <script runat="server">
    
        void return_mac_address (Object sender, EventArgs e)
        {
            GetInfo MyMac=new GetInfo();
            string sMac = MyMac.getMACAddress();
            result.Text= sMac;
        }
    
        void Page_Load (Object sender, EventArgs e)
        {
            if (!Page.IsPostBack) {
                return_mac_address();
            }
        }
    
    
    
    </script>
    <html>
    <head>
    </head>
    <body>
        <form runat="server">
                <br />
                <asp:Label id="result" runat="Server"></asp:Label>
            </select>
        </form>
    </body>
    </html>
    
     Can anoby help me with this please.
     
    Thanks a lot. 
     
     
  • Re: C# Assembly Reference issue ??

    05-08-2008, 11:48 AM
    • Loading...
    • Ken Tucker
    • Joined on 12-23-2003, 1:40 PM
    • Florida
    • Posts 946
    • TrustedFriends-MVPs

     

    You have to add a reference to System.Management in addition to the using statement
  • Re: C# Assembly Reference issue ??

    05-08-2008, 11:52 AM
    • Loading...
    • NemesisMtl
    • Joined on 05-08-2008, 3:38 PM
    • Posts 2

     I'm using Microsoft ASP.NET Web Matrix to code this script. I've added the System.Management in the Classes Panel and still that error. Is it a reference or there's another way to do it.
     

  • Re: C# Assembly Reference issue ??

    05-08-2008, 12:50 PM

     Is there any reason you're using WebMatrix rather than Web Developer express etc?

  • Re: C# Assembly Reference issue ??

    05-08-2008, 4:39 PM
    • Loading...
    • che3358
    • Joined on 09-25-2003, 6:23 AM
    • Cleveland, OH
    • Posts 700

    Kent meant you can't just add using System.Management; to your code. You HAVE to add it in your reference BIN folder first before you add this code. Right click you project, then Add Reference, go to TAB .NET, find system.Management, add it.

Page 1 of 1 (5 items)