Skip to content
Draft
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
7928f29
Initial plan
Copilot Oct 10, 2025
eed5cea
Update switch statements in JsonDecoder and EccUtils to throw for une…
Copilot Oct 10, 2025
95db7d3
Update switch statements in DataGenerator to throw for unexpected values
Copilot Oct 10, 2025
689cb7f
Update switch statements in RelativePath to throw for unexpected Elem…
Copilot Oct 10, 2025
1812511
Add comprehensive documentation for switch statement refactoring
Copilot Oct 10, 2025
887d18b
Update Stack/Opc.Ua.Core/Types/Utils/DataGenerator.cs
marcschier Oct 11, 2025
ce8c2a3
Update Stack/Opc.Ua.Core/Types/Utils/DataGenerator.cs
marcschier Oct 11, 2025
591c98d
Update Stack/Opc.Ua.Core/Types/Utils/DataGenerator.cs
marcschier Oct 11, 2025
c7a55d6
Update
marcschier Oct 12, 2025
b268ca6
Fix merge failure resulting in build failure
marcschier Oct 12, 2025
f6d3689
Update
marcschier Oct 12, 2025
263df1d
Update
marcschier Oct 13, 2025
83f347a
Merge
marcschier Oct 13, 2025
17dc1b8
Updates
marcschier Oct 13, 2025
8a51cd8
Merge branch 'marcschier-patch-1' of https://github.com/OPCFoundation…
marcschier Oct 13, 2025
e15466b
Update
marcschier Oct 14, 2025
119e077
Fix
marcschier Oct 14, 2025
64852a4
Update
marcschier Oct 14, 2025
7e001e9
Update
marcschier Oct 14, 2025
09d7b2b
Revert
marcschier Oct 14, 2025
e81b7b8
Add diagnostics mask when creating sessions. Add additional info to t…
marcschier Oct 14, 2025
c1090b1
Refactor diagnostics and error handling
marcschier Oct 14, 2025
05ee83e
Enable more logging to uncover test issues (temp)
marcschier Oct 15, 2025
5c6abf7
Update dependencies
marcschier Oct 15, 2025
5e73e2f
Debug updates
marcschier Oct 15, 2025
20e0afa
Debug more
marcschier Oct 15, 2025
fec9915
Additional logs
marcschier Oct 15, 2025
58365b1
Merge from master
marcschier Oct 16, 2025
f33870f
Fix logging in unit tests
marcschier Oct 16, 2025
c35de86
Dump exception to unit test logging too.
marcschier Oct 16, 2025
9292e7e
Disable cache
marcschier Oct 16, 2025
2ee8b67
Formatting
marcschier Oct 16, 2025
a5ff40f
Remove certi cache
marcschier Oct 16, 2025
4e45731
Update
marcschier Oct 16, 2025
9de8742
Gets server logs
marcschier Oct 16, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
499 changes: 442 additions & 57 deletions .editorconfig

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ on:
# The branches below must be a subset of the branches above
branches: [ master, main ]
paths:
- '**.cs'
- '**.cs'
schedule:
- cron: '30 6 * * 6'
workflow_dispatch:
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
Expand All @@ -36,14 +36,14 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
uses: github/codeql-action/init@v4
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

- name: Set up .NET
uses: actions/setup-dotnet@v5
with:
Expand All @@ -58,11 +58,11 @@ jobs:
run: |
nuget restore "UA Core Library.sln"
nuget restore "UA Reference.sln"

- name: Build Solution
run: |
msbuild.exe "UA Core Library.sln" /p:configuration="Release" /p:UseSharedCompilation=false
msbuild.exe "UA Reference.sln" /p:configuration="Release" /p:UseSharedCompilation=false

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
uses: github/codeql-action/analyze@v4
16 changes: 15 additions & 1 deletion Applications/ConsoleReferencePublisher/PublishedValuesWrites.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ public void Start()
case kDataSetNameAllTypes:
m_allTypesFields.AddRange(publishedDataSet.DataSetMetaData.Fields);
break;
default:
m_logger.LogInformation(
"PublishedValuesWrites.Start: {DataSet} unknown.",
publishedDataSet.Name);
break;
}
}
}
Expand Down Expand Up @@ -308,6 +313,9 @@ private void UpdateValues(object state)
case "DateTime":
IncrementValue(variable, NamespaceIndexSimple);
break;
default:
m_logger.LogDebug("{Variable} not processed.", variable.Name);
break;
}
}

Expand All @@ -332,6 +340,7 @@ private void UpdateValues(object state)
/// <param name="namespaceIndex"></param>
/// <param name="maxAllowedValue"></param>
/// <param name="step"></param>
/// <exception cref="ServiceResultException"></exception>
private void IncrementValue(
FieldMetaData variable,
ushort namespaceIndex,
Expand All @@ -351,7 +360,8 @@ private void IncrementValue(

bool valueUpdated = false;

switch (TypeInfo.GetBuiltInType(variable.DataType))
BuiltInType builtInType = TypeInfo.GetBuiltInType(variable.DataType);
switch (builtInType)
{
case BuiltInType.Boolean:
if (variable.ValueRank == ValueRanks.Scalar)
Expand Down Expand Up @@ -505,6 +515,10 @@ private void IncrementValue(
valueUpdated = true;
}
break;
case >= BuiltInType.Null and <= BuiltInType.Enumeration:
break;
default:
throw ServiceResultException.Unexpected($"Unexpected BuiltInType {builtInType}");
}

if (valueUpdated)
Expand Down
6 changes: 6 additions & 0 deletions Applications/Quickstarts.Servers/Alarms/AlarmHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* ======================================================================*/

using System;
using System.Diagnostics;
using Opc.Ua;

namespace Alarms
Expand Down Expand Up @@ -117,6 +118,11 @@ public static BaseDataVariableState CreateVariable(
variable.DataType = DataTypeIds.Double;
variable.Value = (double)AlarmDefines.NORMAL_START_VALUE;
break;
default:
Debug.Fail($"Unexpected data type {dataTypeIdentifier}");
variable.DataType = DataTypeIds.Int32;
variable.Value = AlarmDefines.NORMAL_START_VALUE;
break;
}
variable.ValueRank = ValueRanks.Scalar;
variable.AccessLevel = AccessLevels.CurrentReadOrWrite;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using Microsoft.Extensions.Logging;
using Opc.Ua;
Expand Down
38 changes: 17 additions & 21 deletions Applications/Quickstarts.Servers/MemoryBuffer/MemoryBufferState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,7 @@ public MemoryBufferState(

SymbolicName = name;

BuiltInType elementType = BuiltInType.UInt32;

switch (dataType)
{
case "Double":
elementType = BuiltInType.Double;
break;
}
BuiltInType elementType = dataType != "Double" ? BuiltInType.UInt32 : BuiltInType.Double;

CreateBuffer(elementType, count);
}
Expand Down Expand Up @@ -131,14 +124,7 @@ public void CreateBuffer(string elementName, int noOfElements)
elementName = "UInt32";
}

BuiltInType elementType = BuiltInType.UInt32;

switch (elementName)
{
case "Double":
elementType = BuiltInType.Double;
break;
}
BuiltInType elementType = elementName != "Double" ? BuiltInType.UInt32 : BuiltInType.Double;

CreateBuffer(elementType, noOfElements);
}
Expand All @@ -148,13 +134,12 @@ public void CreateBuffer(string elementName, int noOfElements)
/// </summary>
/// <param name="elementType">The type of element.</param>
/// <param name="noOfElements">The number of elements.</param>
/// <exception cref="ServiceResultException"></exception>
public void CreateBuffer(BuiltInType elementType, int noOfElements)
{
lock (m_dataLock)
{
ElementType = elementType;
m_elementSize = 1;

switch (ElementType)
{
case BuiltInType.UInt32:
Expand All @@ -163,6 +148,11 @@ public void CreateBuffer(BuiltInType elementType, int noOfElements)
case BuiltInType.Double:
m_elementSize = 8;
break;
case >= BuiltInType.Null and <= BuiltInType.Enumeration:
m_elementSize = 1;
break;
default:
throw ServiceResultException.Unexpected($"Unexpected BuiltInType {ElementType}");
}

m_lastScanTime = DateTime.UtcNow;
Expand Down Expand Up @@ -255,6 +245,7 @@ public ServiceResult ReadTagValue(
/// <summary>
/// Handles a write operation for an individual tag.
/// </summary>
/// <exception cref="ServiceResultException"></exception>
public ServiceResult WriteTagValue(
ISystemContext context,
NodeState node,
Expand Down Expand Up @@ -332,8 +323,10 @@ public ServiceResult WriteTagValue(
bytes = BitConverter.GetBytes(valueToWrite.Value);
break;
}
default:
case >= BuiltInType.Null and <= BuiltInType.Enumeration:
return StatusCodes.BadNodeIdUnknown;
default:
throw ServiceResultException.Unexpected($"Unexpected BuiltInType {ElementType}");
}

for (int ii = 0; ii < bytes.Length; ii++)
Expand All @@ -358,6 +351,7 @@ public ServiceResult WriteTagValue(
/// <summary>
/// Returns the value at the specified offset.
/// </summary>
/// <exception cref="ServiceResultException"></exception>
public Variant GetValueAtOffset(int offset)
{
lock (m_dataLock)
Expand All @@ -378,9 +372,11 @@ public Variant GetValueAtOffset(int offset)
return new Variant(BitConverter.ToUInt32(m_buffer, offset));
case BuiltInType.Double:
return new Variant(BitConverter.ToDouble(m_buffer, offset));
case >= BuiltInType.Null and <= BuiltInType.Enumeration:
return Variant.Null;
default:
throw ServiceResultException.Unexpected($"Bad element type {ElementType}");
}

return Variant.Null;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,12 @@ private static bool IsAnalogType(BuiltInType builtInType)
case BuiltInType.Float:
case BuiltInType.Double:
return true;
case >= BuiltInType.Null and <= BuiltInType.Enumeration:
return false;
default:
Debug.Fail($"Unexpected BuiltInType {builtInType}");
return false;
}
return false;
}

private static Range GetAnalogRange(BuiltInType builtInType)
Expand All @@ -141,7 +145,10 @@ private static Range GetAnalogRange(BuiltInType builtInType)
return new Range(double.MaxValue, double.MinValue);
case BuiltInType.Byte:
return new Range(byte.MaxValue, byte.MinValue);
case >= BuiltInType.Null and <= BuiltInType.Enumeration:
return new Range(sbyte.MaxValue, sbyte.MinValue);
default:
Debug.Fail($"Unexpected BuiltInType {builtInType}");
return new Range(sbyte.MaxValue, sbyte.MinValue);
}
}
Expand Down
4 changes: 2 additions & 2 deletions Applications/Quickstarts.Servers/TestData/TestDataSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -566,9 +566,9 @@ public object ReadValue(BaseVariableState variable)
case Variables.Data_Static_Structure_ScalarStructure_UIntegerValue:
case Variables.Data_Dynamic_Structure_ScalarStructure_UIntegerValue:
return new Variant(m_generator.GetRandomUInteger());
default:
return null;
}

return null;
}
}

Expand Down
8 changes: 4 additions & 4 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
<PackageVersion Include="Newtonsoft.Json" Version="13.0.4" />
<PackageVersion Include="NUnit" Version="4.4.0" />
<PackageVersion Include="NUnit.Console" Version="3.20.1" />
<PackageVersion Include="NUnit3TestAdapter" Version="5.1.0" />
<PackageVersion Include="NUnit3TestAdapter" Version="5.2.0" />
<PackageVersion Include="PolySharp" Version="1.15.0" />
<PackageVersion Include="Roslynator.Analyzers" Version="4.14.0" />
<PackageVersion Include="Roslynator.Formatting.Analyzers" Version="4.14.0" />
<PackageVersion Include="Roslynator.Analyzers" Version="4.14.1" />
<PackageVersion Include="Roslynator.Formatting.Analyzers" Version="4.14.1" />
<PackageVersion Include="SharpFuzz" Version="2.2.0" />
<PackageVersion Include="Serilog" Version="4.3.0" />
<PackageVersion Include="Serilog.Expressions" Version="5.0.0" />
Expand All @@ -46,7 +46,7 @@
<PackageVersion Include="System.IO.Compression" Version="4.3.0" />
<PackageVersion Include="System.Net.NetworkInformation" Version="4.3.0" />
<PackageVersion Include="System.Collections.Immutable" Version="9.0.9" />
<PackageVersion Include="System.Text.Json" Version="9.0.5" />
<PackageVersion Include="System.Text.Json" Version="9.0.9" />
<PackageVersion Include="System.Private.Uri" Version="4.3.2" />
<PackageVersion Include="System.Runtime.InteropServices.RuntimeInformation" Version="4.3.0" />
<PackageVersion Include="System.Security.Cryptography.Cng" Version="5.0.0" />
Expand Down
6 changes: 3 additions & 3 deletions Fuzzing/Encoders/Fuzz/FuzzableCode.BinaryDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,10 @@ internal static IEncodeable FuzzBinaryDecoderCore(
{
return null;
}
break;
goto default;
default:
throw;
}

throw;
}
}

Expand Down
6 changes: 3 additions & 3 deletions Fuzzing/Encoders/Fuzz/FuzzableCode.JsonDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ internal static IEncodeable FuzzJsonDecoderCore(string json, bool throwAll = fal
{
return null;
}
break;
goto default;
default:
throw;
}

throw;
}
}
}
Expand Down
15 changes: 7 additions & 8 deletions Fuzzing/Encoders/Fuzz/FuzzableCode.XmlDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,14 @@ internal static IEncodeable FuzzXmlDecoderCore(Stream stream, bool throwAll = fa
{
return null;
}
break;
goto default;
default:
Console.WriteLine(
"Unexpected ServiceResultException: {0} {1}",
(StatusCode)sre.StatusCode,
sre.Message);
throw;
}

Console.WriteLine(
"Unexpected ServiceResultException: {0} {1}",
(StatusCode)sre.StatusCode,
sre.Message);

throw;
}
}
}
Expand Down
12 changes: 9 additions & 3 deletions Libraries/Opc.Ua.Client.ComplexTypes/ComplexTypeSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -1305,8 +1306,14 @@ private static bool IsAllowSubTypes(StructureDefinition structureDefinition)
case StructureType.UnionWithSubtypedValues:
case StructureType.StructureWithSubtypedValues:
return true;
case StructureType.Structure:
case StructureType.StructureWithOptionalFields:
case StructureType.Union:
return false;
default:
Debug.Fail($"Unexpected StructureType {structureDefinition.StructureType}.");
return false;
}
return false;
}

private async Task<bool> IsAbstractTypeAsync(
Expand Down Expand Up @@ -1479,8 +1486,7 @@ private static void SplitAndSortDictionary(
}
else
{
throw ServiceResultException.Create(
StatusCodes.BadUnexpectedError,
throw ServiceResultException.Unexpected(
"Unexpected Type in binary schema: {0}.",
item.GetType().Name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,15 +373,16 @@ private static NodeId ToNodeId(
return DataTypeIds.BaseDataType;
case "ExtensionObject":
return DataTypeIds.Structure;
default:
System.Reflection.FieldInfo internalField = typeof(DataTypeIds).GetField(
typeName.Name);
if (internalField == null)
{
// The type was not found in the internal type factory.
return NodeId.Null;
}
return (NodeId)internalField.GetValue(typeName.Name);
}
System.Reflection.FieldInfo internalField = typeof(DataTypeIds).GetField(
typeName.Name);
if (internalField == null)
{
// The type was not found in the internal type factory.
return NodeId.Null;
}
return (NodeId)internalField.GetValue(typeName.Name);
}
if (!typeCollection.TryGetValue(typeName, out NodeId referenceId))
{
Expand Down
Loading
Loading