1029 Commits

Author SHA1 Message Date
opcfoundation-org e03883abe8 Fix JsonDecoder for Unions. (#3323)
Co-authored-by: Randy Armstrong <randy@sparhawksoftware.com>
2025-11-07 13:21:59 +01:00
Marc Schier dad5dc6a87 Pull ActivityTraceFlags into IClientBase (#3319)
* Pull ActivityTraceFlags into IClientBase
* Update node parsing
* Ensure no 0 request id and revert unique request id
2025-11-05 16:51:02 +01:00
Marc Schier b5044212f0 Allow sending while connecting in client channel. (#3315)
- Remove ConnectAsync from lock. Useable means m_channel is set, not useable means it is null.
- Add comments on lock behavior during connection.
- Remove callback log from validator
- Change TCS creation to specify run continuations async
- Fix encoder factory reflecting every time it is created.
2025-11-05 15:37:36 +01:00
Marc Schier bad6bf416b Trace and metrics for send/receive, more test coverage and additional nullable annotations (#3314)
Refactored client-side logic to support batching of service requests, ensuring compliance with operation limits and improving scalability. Added telemetry and activity tracing using `ActivityTraceFlags` for better observability, including metrics collection and logging. Enhanced error handling with descriptive exception messages and improved certificate validation.

Introduced a comprehensive suite of unit tests for `SessionClientBatchTests.cs` and `ClientBaseTests.cs`, covering batching, error scenarios, and edge cases. Added helper classes for testing logging, metrics, and activity tracing. Updated tests to align with modern C# practices, including nullable reference types and collection initializers.

Improved code consistency, readability, and maintainability by standardizing method signatures, simplifying redundant patterns, and removing legacy constructs. Updated XML documentation and added conditional compilation for .NET 8.0+ compatibility.
2025-11-05 11:16:28 +01:00
romanett b422ed18a7 Configure Thread Pool for better Server Performance (#3310) 2025-11-02 14:17:48 +01:00
Marc Schier 1c178402ad Refactor client state persistence and add more tests (#3303)
* State handling and better serialization
* Nullable for almost everything  inclient library
* Additional testing of session
2025-11-01 17:18:48 +01:00
Copilot 7626d82aa1 Add TryParse methods to NodeId and ExpandedNodeId (#3302)
* Initial plan

* Add TryParse methods to NodeId and ExpandedNodeId with comprehensive tests

Co-authored-by: marcschier <11168470+marcschier@users.noreply.github.com>

* Address code review feedback: use explicit Exception catch and improve consistency

Co-authored-by: marcschier <11168470+marcschier@users.noreply.github.com>

* Refactor TryParse to be core implementation, Parse now calls TryParse

Changed architecture so TryParse contains the parsing logic without throwing exceptions.
Parse methods now call TryParse and throw appropriate exceptions on failure.
This avoids using try-catch for control flow as requested.

All 1643 BuiltInType tests pass.

Co-authored-by: marcschier <11168470+marcschier@users.noreply.github.com>

* Refactor ExpandedNodeId InternalTryParse to avoid creating object in try-catch

Reworked the static InternalTryParse method to directly parse ExpandedNodeId
components without creating an ExpandedNodeId object and catching exceptions.

Also refactored the instance InternalParse method to use a new InternalTryParseInstance
helper that implements TryParse pattern, with InternalParse calling it and throwing
appropriate exceptions (ArgumentException or ServiceResultException) on failure.

All 1643 BuiltInType tests pass.

Co-authored-by: marcschier <11168470+marcschier@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: marcschier <11168470+marcschier@users.noreply.github.com>
2025-11-01 09:36:21 +01:00
Suciu Mircea Adrian 1f47847324 Added RejectCertificateUriMismatch property and explicit ApplicationUri validation after certificates are loaded (#3244)
* Added RejectCertificateUriMismatch property and explicit ApplicationUri validation after certificates are loaded

* Perform duplicate detection on thumbprint only

* Ported handle multiple ApplictionUri, removed assign ApplictionUri from certificate

* Missing letter

* Fixed LoadPrivateKeyAsync when no applicationUri is passed.

* Add tests for validating certificates with multiple AplicationUris on ApplicationInstance level and server side

* Renamed into CheckOrCreateCertificateAsync, logged Certificate, improved tests

* Added retry logic for transient connect errors in CreateSessionApplicationUriValidationTests

* Added TODO log when telemetry instance available

* Removed unused ValidateServerCertificateApplicationUri(X509Certificate2 serverCertificate)
2025-10-31 14:17:31 +01:00
Marc Schier 8d2286305a 1.05.06 generated files (#3299)
* Update to 1.05.06 generated files.

* Update generated files to 1.05.06.

* fix GDS build

---------

Co-authored-by: Randy Armstrong <randy@sparhawksoftware.com>
Co-authored-by: Roman Ettlinger <romanett98@gmail.com>
2025-10-30 15:33:42 +01:00
romanett 820f6a293c [Server] Refactor Publishing to work with TAP (#3289) 2025-10-30 05:36:54 +01:00
Marc Schier fab6f2ac1a [Client] Obsolete APM calls (#3282)
* Refactor for robustness and async improvements

Refactored code to enhance robustness and maintainability by enabling nullable reference types and using `async`/`await` for asynchronous operations. Updated exception handling to use `BadNotConnected()` for more accurate error states. Removed unused code and improved test files to align with these changes. Introduced `OpenInternalAsync` for better channel management and handled on-demand connection creation in `SendRequestAsync`.

* Obsolete APM
* Remove WCF remainders, channel clean up and initial cut at Channel factory
* Clean up copyright notice formatting
* Make connect async in Socket and abstract bindings for easier testing
* Fix unit tests

These changes enhance robustness, maintainability, and correctness of channel and task management.

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Roman Ettlinger <romanett98@gmail.com>
2025-10-24 13:37:59 +02:00
Copilot 62b3ada536 Fix NodeId.Parse() to reject invalid identifiers without type prefix (#3284)
* Fix NodeId.Parse() to reject invalid identifiers without proper prefix

- Modified NodeId.InternalParse() to distinguish between namespace URI (from ExpandedNodeId) and namespace index (from ns=)
- Only allow implicit string identifiers when namespace URI is specified (nsu=), not when namespace index is specified (ns=)
- Added test case NodeIdParseInvalidWithNamespace to verify invalid NodeIds are rejected
- Fixed existing tests that were relying on the buggy behavior

Co-authored-by: marcschier <11168470+marcschier@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: marcschier <11168470+marcschier@users.noreply.github.com>
2025-10-24 11:14:11 +02:00
Marc Schier f8042e445c Check bounds for switched on values and roslyn cleanup (#3264) 2025-10-21 09:28:19 +02:00
Suciu Mircea Adrian 8152feec71 Allow non OPC-UA conform SubjectName values to AddSecurityConfigurationStores (#3229)
* Replace fuzzy search with SimpleName search if comparing DistinguishedName fails.

* Added mandatory Organization Name attribute to SetSuitableDefaults().
Added Test for the special case.

* Added missing O attribute to CompareDistinguishedName call

* Update test

* CertificateIdentifier.Find will pick the certificate with the longest duration

* Find only valid certificates.

* Prioritizes CA-signed certificates over self-signed certificates

* Update Tests/Opc.Ua.Configuration.Tests/ApplicationInstanceTests.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Select longest remaining validity if valid, or least expired if all expired

* Renamings

* Improved comments, improved algo clarity and taken into account more possible cases of prioritization depending on cert validity

* Comment corrected

---------

Co-authored-by: romanett <romanett98@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-10-21 09:26:29 +03:00
Marc Schier ff0095c93d Make GDS tests stable and add better logging to unit tests (#3271)
- Allow setting ReturnDiagnostics on the session factory to ensure the diagnostic settings are part of "Create" also.  Set them to SymbolicIdAndText by default.
- Better logging in unit tests, now also logs to progress including exception traces, also prefixes SERVER and TEST on console to attach the logs to the server or client side.
- GDS client stability improvements to ensure client reliably reconnects between calls when connection is lost.
- Do not dispose the application certificate when it is updated from GDS client to avoid existing sessions to crash with CryptographicException.  This needs more improvements later on because it is rather hacky today.
- Remove the certificate cache in CertificateFactory (as per discussion and agreement) which allowed re-enabling the older UserIdentity API
- Logging improvements here and there to analyze issues in unit tests better
2025-10-20 18:02:45 +02:00
Marc Schier ca43b642b6 Fix WriteArray in encoders to also write null. (#3266)
* Add test to test encoding "Null" array and expect empty array or null to be decoded.
* Apply suggestions from code review

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-10-16 08:24:20 +02:00
Copilot 8c9ccc4477 Replace deprecated Uri.DnsSafeHost with Uri.IdnHost (#3256)
* Replace deprecated Uri.DnsSafeHost with Uri.IdnHost across codebase

Co-authored-by: marcschier <11168470+marcschier@users.noreply.github.com>

* Update Kestrel.Core package version to 2.3.6
* Fix privateKeyPassword handling in GDS client

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: marcschier <11168470+marcschier@users.noreply.github.com>
Co-authored-by: Marc Schier <marcschier@hotmail.com>
Co-authored-by: Marc Schier <marcschier@users.noreply.github.com>
2025-10-16 08:18:04 +02:00
romanett 2bee7e195d [Client] Set default timout hint based on OperationTimeout of the TransportChannel (#3178)
* Set a default TimeoutHint in all request based on the OperationTimeout

* simplify calculation

* Add new TimeOutHintProperty and bounds checks

* fix build

* fix build
2025-10-13 07:44:21 +02:00
Copilot 7560307a91 Fix log level for expected client disconnection scenarios (BadNoSubscription and related status codes) (#3255)
* Initial plan

* Change log level from Warning to Information for expected disconnection status codes

Co-authored-by: romanett <7413710+romanett@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: romanett <7413710+romanett@users.noreply.github.com>
2025-10-12 07:59:02 +02:00
Marc Schier e505800c74 Refactor string usage for secrets (#394) (#3250)
* Refactor string usage for secrets (#394)

Strings are immutable and the lifetime of secrets can not be controlled.
Use byte[] or char[] instead of strings for secrets, which can be erased
after use.

* Clear pw

---------

Co-authored-by: Martin Regen <7962757+mregen@users.noreply.github.com>
2025-10-12 03:00:36 +02:00
Marc Schier 4c651d05d2 Improve test stability of ValidateTransfer test, ensure thread safety in MonitoredItem (#3243)
* Improve thread safety and logging in MonitoredItem

Replaced Queue with ConcurrentQueue in MonitoredItemDataCache
for thread-safe operations. Updated Publish method to use
List<DataValue> for better handling of dequeued values. Enhanced
logging to include SourceTime and added logs for dropped values.

In DurableSubscriptionTest, added try-finally block to ensure
proper session closure and disposal, preventing memory leaks.
Introduced DurableSubscriptionTestLooper for stress testing
under debug mode. Refactored test code for improved readability.

* Improve logging and session management

Updated logging in `Session.cs`, `ServerBase.cs`, and `UaSCBinaryClientChannel.cs` to pass exceptions directly to the logger, enhancing error handling. Added connection state checks in `Session.cs` to prevent operations when the session is closed or never connected. Updated `Subscription.cs` to reflect session disconnection in `PublishingStopped`. Enhanced test outputs and renamed `DurableSubscriptionTestLooper` to `DurableSubscriptionTestDebug` in `DurableSubscriptionTest.cs`, reducing loop count for faster debug testing.

* Fix monitored item id factory producing collisions by first trying to allocate a free monitored item id in the table, then committing.

* Better diffing

* Enhance logging and session management

Added detailed logging in `AlarmNodeManager.cs` for lifecycle events and simulation control. Introduced a `Reconnecting` property in the `ISession` interface and `Session.cs` to manage session reconnection state, replacing the `m_reconnecting` field. Enhanced logging in `Session.cs` for reconnection and publish operations. Updated `DataGenerator.cs` to use `FrozenDictionary` for performance improvements. Replaced `SyncRoot` with `m_syncRoot` in `NamespaceTable.cs` for synchronization. Improved exception message formatting in `ServiceResult.cs`. Added necessary namespaces for new data structures. Made corrections and added debugging in `DurableSubscriptionTest.cs` for better session handling.

* Dispose simulation
2025-10-11 19:51:38 +02:00
Marc Schier 01ffcee410 Immutable Encodeable factory and lookup performance improvements (#3241) 2025-10-08 09:45:32 +02:00
Copilot 59c7458ee1 Fix InvalidCastException in GetBrowseName methods for Attributes, DataTypes, ReferenceTypes, and StatusCodes (#3242)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: marcschier <11168470+marcschier@users.noreply.github.com>
2025-10-08 09:45:08 +02:00
Marc Schier 95201819a1 More missing obsoleted API to support better porting (#3237) 2025-10-06 12:06:33 +02:00
Marc Schier 845c31d33b Add API back as Obsolete for samples to compile (almost) unchanged. (#3234)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-10-03 14:20:21 +02:00
Marc Schier 8e7a73c7df Introduce telemetry context and proper use of ILogger (#3213) 2025-09-25 20:25:31 +02:00
romanett 7cbf817f1b Improve thread safe Utils methods for incrementing identifiers (#3221) 2025-09-22 17:33:54 +02:00
Marc Schier 2dbff3a8af Fix #3209 (#3211) 2025-09-18 09:18:33 +03:00
romanett 9ba17b2334 [Server] Extend MasterNodeManager with support for ReadAsync, WriteAsync, HistoryReadAsync, HistoryWriteAsync, TranslateBrowsePathAsync, ConditionRefreshAsync (#3188)
* Add ReadAsync, WriteAsync, Service calls
* Add HistoryReadAsync
* Add HistoryUpdateAsync
* Add ConditionRefreshAsync & TranslateBrowsePathAsync
* Add BrowseNextAsync & BrowseAsync
* Warnings on sync call

---------

Co-authored-by: Marc Schier <marcschier@users.noreply.github.com>
2025-09-11 13:11:11 +02:00
romanett 4cf9fb8428 Make IAsyncNodeManager experimental / Remove deprecated ICertificateStoreMembers / Rename IApplicationConfigurationBuilderCreate.Create to CreateAsync (#3187)
* Make IAsyncNodeManager experimental
* Remove deprecated ICertificateStore Members
* rename IApplicationConfigurationBuilderCreate Create method to CreateAsync
* Add obsolete create
2025-09-11 08:27:40 +02:00
romanett 0f031aad93 [Server] Implement async transportlistener callback (#3184)
* Implement TAP Async TransportListenerCallback
* fix build add support for TimeoutHint
* disable async publish
2025-09-11 08:26:24 +02:00
Marc Schier 6d5254745d Move newly introduced AsyncNodeTable and AsyncTypeTree interfaces to core (#3182)
* Move new interfaces to core

* Add extension methods to convert from async to sync tables
2025-09-03 14:48:34 +02:00
Marc Schier 520351ccfc Optimize reflection-based lookups using caches (#3179)
* Optimize lookups using reflection using caches,  Cleanup code.
2025-08-28 18:39:16 -07:00
Marc Schier 25ba2a2d08 Make sync client api obsolete (#3174) 2025-08-27 06:05:36 -07:00
romanett a86077ac38 Make GDS Tests use ECC for connection. Update Certificate wait check to use polling mechanism. (#3167)
* Update GDS Client to use async Client API
* Make GDS Tests use ECC for connection. Update Certifiacte wait check to use polling mechanism
* Use Async Server Methods
* Add specialized ECC Test procdure
* Add Exception handling to allow errors during server application certificate exchange

---------

Co-authored-by: Marc Schier <marcschier@users.noreply.github.com>
2025-08-22 16:55:25 +02:00
Marc Schier 954f2ba063 Fix nuget and official build and additional smaller analzyer fixes (#3166)
* Add strong namer
* Add suppression files
* Fix 462 build
2025-08-19 16:42:03 +02:00
Marc Schier 9830e5d53e Enable roslynizer and fix all analyzer issues (#3157)
* Fix warnings and suggestions
* Enable roslynator
2025-08-16 04:10:24 -07:00
romanett 62aa1fa053 Remove exception in ServiceResult Call() (#3155)
Co-authored-by: Randy Armstrong <randy@sparhawksoftware.com>
2025-08-12 14:52:51 +02:00
romanett cae5fb25da [Server] Implement Support for Async Method Calls (#3090)
* Implement support for async method Call in the server
* Implement Cancellation
* Add new generated async supported Endpoints & Server Methods
* Make SecureChannelContext AsyncLocal
* Implement SubscriptionAsync
* Add Async Request Queue
* Implement sync calls for async NodeManagers. Add Warning
* Use second file for Async Interface
2025-08-12 10:44:57 +02:00
romanett 751d614dc6 make ICertificateStore use Async suffixes (#3148) 2025-08-08 12:24:03 +02:00
romanett d4e44c6311 Add async suffix to methods returning a Task (#3145)
* Add async suffix to asnyc methods
2025-08-07 13:55:15 +02:00
romanett f460736582 remove all obsolete methods from the stack (#3139) 2025-08-06 21:27:10 +02:00
romanett 92c3cb674d Extend Existing Server Interfaces (ISessionManager, ISubscriptionManager, IServerInternal) (#3099)
* Extend Existing Server Interfaces

* Update GDS

* cleanup

* Add Store / Restore Methods to ISubscriptionManager

* Apply suggestions from code review

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Marc Schier <marcschier@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-08-06 21:24:36 +02:00
romanett fb5d6edc62 Fix Analyzer warnings (#3143) 2025-08-06 19:14:00 +02:00
romanett 1f6ad6b531 [Server] Handle unsent requests on closed SecureChannel to be sent on new channel of the same session (#3132)
* Extend the TcpTransportListener to catch requests that failed to get sent by a TcpServerChannel because the channel was closed. The TcpTransportListener asks the ServerCallback for the new ChannelID of the Session. The Session is identitfied by the AuthenticationToken

* throw if no channel could be found

* dont send request again over the same channel
2025-07-31 20:42:33 +02:00
Marc Schier 876cf28c32 Fix subscription leaking due to not completed PublishResponseMessageWorkerAsync tasks (#3133) 2025-07-31 17:31:21 +02:00
Marc Schier 5eb9ed8918 Backporting changes in preparation of adding additional fuzz tests (in separate PR) (#3125)
- Replaced `IList<INode>` with `List<INode>` in
  `ComplexTypeSystem.cs` and `BaseComplexType.cs` for
  better type safety.
- Updated string comparison in `ReverseConnectManager.cs`
  to `StringComparison.Ordinal` for improved performance.
- Added a method to `ISession.cs`, `Session.cs`, and
  `SessionAsync.cs` to trigger reloading instance certificates.
- Minor fixes in error handling in `Subscription.cs` and using pattern matching for type checks in several locations to improve code readability.
- Made minor adjustments to comments and documentation
  for clarity and improved code quality.
- Updated `Variant` handling in preparation for immutable struct.
- Changed return types in `BaseObjectState.cs` and `BaseVariableTypeState.cs` to use `ObjectTypeIds` for iperf
- Cleaned up `ExpandedNodeId`
- Enhanced memory management  error handling and readabilityand error handling in encoders
2025-07-31 15:54:42 +02:00
opcfoundation-org b823127c61 Update for 1.5.5 release with Async Service Calls (#3116)
* Update for 1.5.5 release with Async Service Calls

* Fix Async Method Handlers.

---------

Co-authored-by: Randy Armstrong <randy@sparhawksoftware.com>
2025-07-29 14:42:24 +03:00
romanett 40b9dbb29e Implement Support for PEM Public Keys in Directory Certificate Store (#3088)
* Implement search of certificates in PEM files on net 6 in directory store

* Implement using Custom Certificate Store

* Cleanup

* Implement Support for PEM Public Keys in Directory Store

* Throw exception if test file is  not found

* Skip Tests on Mac OS & Net < 8.0

* Add delay for slow CI Agents

* Add more delay

* Make test file with explicit message

* Address review Feedback

* fix test

* Throw ex to show possible error in test

* next try

* Only throw on full load

* Manually set LastWriteTimeUtc

* make private key encrypted, use two separate tests instead of one

---------

Co-authored-by: Marc Schier <marcschier@users.noreply.github.com>
2025-07-25 12:36:38 +03:00
romanett bd6c91d6df Use Central Package Management for Nuget Packages (#3122)
* Use Central Package Management

* Add Directory.Packages.props to solution files

* remove sourcelink version from common.props

* remove old entry from signlist
2025-07-18 10:53:26 +03:00