diff --git a/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Edge.Discovery/src/Services/DiscoveryServices.cs b/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Edge.Discovery/src/Services/DiscoveryServices.cs index 29e3ae0612..0bdd378c0b 100644 --- a/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Edge.Discovery/src/Services/DiscoveryServices.cs +++ b/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Edge.Discovery/src/Services/DiscoveryServices.cs @@ -361,7 +361,7 @@ private async Task> DiscoverServersAsync( request.Token.ThrowIfCancellationRequested(); var resolved = await ep.TryResolveAsync(); var url = new Uri($"opc.tcp://" + resolved); - discoveryUrls.Add(ep, url); + discoveryUrls.AddOrUpdate(ep, url); } request.Token.ThrowIfCancellationRequested(); @@ -426,16 +426,18 @@ private async Task> DiscoverServersAsync( /// private async Task> GetDiscoveryUrlsAsync( IEnumerable discoveryUrls) { + var result = new Dictionary(); if (discoveryUrls?.Any() ?? false) { var results = await Task.WhenAll(discoveryUrls .Select(GetHostEntryAsync) .ToArray()); - return results + foreach (var entry in results .SelectMany(v => v) - .Where(a => a.Item2 != null) - .ToDictionary(k => k.Item1, v => v.Item2); + .Where(a => a.Item2 != null)) { + result.AddOrUpdate(entry.Item1, entry.Item2); + } } - return new Dictionary(); + return result; } ///