0

Following script to read MAC address in C# and working fine for .Net Framework 4

macAddr =
    (
        from nic in NetworkInterface.GetAllNetworkInterfaces()
        where nic.OperationalStatus == OperationalStatus.Up
        select nic.GetPhysicalAddress().ToString()

    ).FirstOrDefault();

But the problem is I need to build it for .Net Framework 3

When I use .Net Framework 3 then following error occurs

Could not find an implementation of the query pattern for source type 'System.Net.NetworkInformation.NetworkInterface[]'. 'Where' not found. Are you missing a reference or a using directive for 'System.Linq'?
(are you missing an assembly reference?)

What will be the solution. Thanks in advance

MD SHAHIDUL ISLAM
  • 14,325
  • 6
  • 82
  • 89

2 Answers2

1

Since you are in .net version 3.0 you cannot use Linq query as above. Use a simple foreach loop as shown below to iterate through the list and fetch the value.

foreach(var nic in NetworkInterface.GetAllNetworkInterfaces())
{
   if(nic.OperationalStatus == OperationalStatus.Up)
   {
    return nic.GetPhysicalAddress();
   }
}
return string.Empty();
Carbine
  • 7,849
  • 4
  • 30
  • 54
0

The feature System.Linq was introduced in the .NET Framework 3.5. Please refer this link https://msdn.microsoft.com/en-us/library/system.linq(v=vs.90).aspx

If you are using .NET 3.5 then add the update the references.

Thiru
  • 3,293
  • 7
  • 35
  • 52