diff --git a/src/OpcSession.cs b/src/OpcSession.cs index d310ad0..1fec619 100644 --- a/src/OpcSession.cs +++ b/src/OpcSession.cs @@ -475,7 +475,7 @@ namespace Opc.Ua.Publisher try { // find a subscription we could the node monitor on - OpcSubscription opcSubscription = OpcSubscriptions.DefaultIfEmpty(null).First(s => s.RequestedPublishingInterval == publishingInterval); + OpcSubscription opcSubscription = OpcSubscriptions.DefaultIfEmpty(null).FirstOrDefault(s => s.RequestedPublishingInterval == publishingInterval); // if there was none found, create one if (opcSubscription == null) { @@ -488,7 +488,7 @@ namespace Opc.Ua.Publisher } // if it is already there, we just ignore it, otherwise we add a new item to monitor. - OpcMonitoredItem opcMonitoredItem = opcSubscription.OpcMonitoredItems.DefaultIfEmpty(null).First(m => m.StartNodeId == nodeId); + OpcMonitoredItem opcMonitoredItem = opcSubscription.OpcMonitoredItems.DefaultIfEmpty(null).FirstOrDefault(m => m.StartNodeId == nodeId); if (opcMonitoredItem == null) { // add a new item to monitor @@ -608,7 +608,7 @@ namespace Opc.Ua.Publisher { OpcSessionsSemaphore.Wait(); var opcSessions = OpcSessions.Where(s => s.Session != null); - var opcSession = opcSessions.Where(s => s.Session.ConfiguredEndpoint.EndpointUrl.Equals(session.ConfiguredEndpoint.EndpointUrl)).DefaultIfEmpty(null).First(); + var opcSession = opcSessions.Where(s => s.Session.ConfiguredEndpoint.EndpointUrl.Equals(session.ConfiguredEndpoint.EndpointUrl)).DefaultIfEmpty(null).FirstOrDefault(); OpcSessionsSemaphore.Release(); if (!ServiceResult.IsGood(e.Status)) { diff --git a/src/PublisherState.cs b/src/PublisherState.cs index 573d0fb..ec59d17 100644 --- a/src/PublisherState.cs +++ b/src/PublisherState.cs @@ -155,7 +155,7 @@ namespace Publisher try { OpcSessionsSemaphore.Wait(); - opcSession = OpcSessions.DefaultIfEmpty(null).First(s => s.EndpointUri == endpointUri); + opcSession = OpcSessions.DefaultIfEmpty(null).FirstOrDefault(s => s.EndpointUri == endpointUri); if (opcSession == null) { // do nothing if there is no session for this endpoint.