Skip to content

Commit

Permalink
Closes tmds#42 Fixes application crash due to uncaught exception from…
Browse files Browse the repository at this point in the history
… GetLinuxNetworkInterfaces
  • Loading branch information
bruinsg committed Jun 8, 2023
1 parent b628654 commit 702c360
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/Tmds.MDns/ServiceBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ private void StartBrowsing(SynchronizationContext synchronizationContext)

_networkAvailabilityChangedEventHandler = (s, e) =>
{
CheckNetworkInterfaceStatuses(interfaceHandlers);
CheckNetworkInterfaceStatuses(interfaceHandlers);
};
NetworkChange.NetworkAvailabilityChanged += _networkAvailabilityChangedEventHandler;

Expand All @@ -243,7 +243,18 @@ private void CheckNetworkInterfaceStatuses(Dictionary<int, NetworkInterfaceHandl
}

HashSet<NetworkInterfaceHandler> handlers = new HashSet<NetworkInterfaceHandler>(_interfaceHandlers.Values);
var networkInterfaces = NetworkInterface.GetAllNetworkInterfaces();
NetworkInterface[] networkInterfaces = Array.Empty<NetworkInterface>();
try
{
networkInterfaces = NetworkInterface.GetAllNetworkInterfaces();
}
catch (System.ArgumentException)
{
// Workaround for bug reported https://github.com/tmds/Tmds.MDns/issues/42
// and https://github.com/dotnet/runtime/issues/49515
return;
}

foreach (NetworkInterface networkInterface in networkInterfaces)
{
if (networkInterface.NetworkInterfaceType == NetworkInterfaceType.Tunnel)
Expand Down

0 comments on commit 702c360

Please sign in to comment.