diff --git a/src/Tmds.MDns/NetworkInterfaceHandler.cs b/src/Tmds.MDns/NetworkInterfaceHandler.cs index 3403e88..58cbdc1 100644 --- a/src/Tmds.MDns/NetworkInterfaceHandler.cs +++ b/src/Tmds.MDns/NetworkInterfaceHandler.cs @@ -126,9 +126,14 @@ internal void Send(IList> packets) { try { + var socket = _socket; + if (socket == null) + { + return; + } foreach (ArraySegment segment in packets) { - _socket.SendTo(segment.Array, segment.Offset, segment.Count, SocketFlags.None, IPv4EndPoint); + socket.SendTo(segment.Array, segment.Offset, segment.Count, SocketFlags.None, IPv4EndPoint); } } catch @@ -194,7 +199,7 @@ private void OnReceive(IAsyncResult ar) lock (this) { #if NETSTANDARD1_3 - if (args.SocketError != SocketError.Success) + if (args.SocketError != SocketError.Success || _socket == null) { return; } @@ -239,7 +244,7 @@ private void OnReceive(IAsyncResult ar) } } } - } + } if (header.IsResponse && header.IsNoError) { for (int i = 0; i < header.QuestionCount; i++)