Reputation: 14523
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
Upvotes: 0
Views: 87
Reputation: 7903
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();
Upvotes: 1
Reputation: 3373
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.
Upvotes: 0