Skip to content

Commit

Permalink
Fixes an issue in Session.LoadDataTypeSystem. (#2166)
Browse files Browse the repository at this point in the history
Starting with line 1857 a dictionary of namespaces is populated in an defensive manner. If a namespace value can't be read, it is silently ignored. If this happens, it will result in an KeyNotFoundException when populating the imports dictionary.
This fix adds a warning if a namespace value can't be read and populates the imports dictionary also defensivly.
  • Loading branch information
AndreasHeisel committed Jun 1, 2023
1 parent 043a56c commit 266e29b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Libraries/Opc.Ua.Client/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1860,16 +1860,20 @@ public async Task<DataDictionary> LoadDataDictionary(ReferenceDescription dictio
{
namespaces[((NodeId)referenceNodeIds[ii])] = (string)nameSpaceValues[ii];
}
else
{
Utils.LogWarning("Failed to load namespace {0}: {1}", namespaceNodeIds[ii], errors[ii]);
}
}

// build the namespace/schema import dictionary
var imports = new Dictionary<string, byte[]>();
foreach (var r in references)
{
NodeId nodeId = ExpandedNodeId.ToNodeId(r.NodeId, NamespaceUris);
if (schemas.TryGetValue(nodeId, out var schema))
if (schemas.TryGetValue(nodeId, out var schema) && namespaces.TryGetValue(nodeId, out var ns))
{
imports[namespaces[nodeId]] = schema;
imports[ns] = schema;
}
}

Expand Down

0 comments on commit 266e29b

Please sign in to comment.