Commit Graph

888 Commits

Author SHA1 Message Date
opcfoundation-org a2e3fc8157 Update Generated Files with latest 1.5.6. (#3344)
Co-authored-by: Randy Armstrong <randy@sparhawksoftware.com>
2025-11-16 14:56:12 +01:00
romanett 0e4b4619c8 Obsolete Sync Certificate Validator Methods (#3338)
* Obsolete Sync Certificate Validator Methods

* Update Tests

* Use HttpClientHandler directly instead of relying on reflection
2025-11-15 07:04:58 +01:00
romanett e58b759488 [Server] Pass SecureChannelContext explicitly (#3340)
* Pass SecureChannelContext explicitly in the Server Library
2025-11-14 12:00:19 +01:00
romanett 0d78fbf6f6 [Server] Obsolete APM & Sync Methods (#3334)
* Add new Generated files with NET_STANDARD_OBSOLETE_SYNC_SERVER
* Obsolete ProcessRequestAsyncResult
* Activate NET_STANDARD_OBSOLETE_SYNC_SERVER & remove StandardServerSync Methods
* Remove sync calls
2025-11-13 10:46:21 +01:00
Marc Schier 35db52a7a6 Move from .net 9 to .net 10 SDK and build new target framework .net 10 (#3333) 2025-11-13 10:45:47 +01:00
romanett d25caffb03 [Server] ActivateSessionAsync / CreateSessionAsync / FindServersAsync / GetEndpointsAsync / CloseSessionAsync (#3225)
Co-authored-by: Marc Schier <marcschier@users.noreply.github.com>
2025-11-11 21:06:17 +01:00
Marc Schier 8b2f5299b1 Fix strong name signing and IVT (#3331)
* Fix IVT with sn signing and clean up unused constants.
* Update signlists
2025-11-11 13:29:37 +01:00
Marc Schier 712e770fbe Restructure core and built in types into base assembly and nuget (#3326)
This change adds a **new Opc.Ua.Types** nuget that contains core types that do not rely on generated code.  Why the name?  Because almost all code that was in the Types subfolder is part of it, and because we do not want to change the name of the Opc.Ua.Core nuget/assembly because code relies on it.  Any other name like base or bootstrap felt out of place due to the current structure already defining the name "types".  Key design is to depend on only a small set of libraries with limited transitive dependencies, that includes hashcode, logging.abstraction, and for non standard20 builds System.Text.Json (needed for localizedText mul parsing).  Also, key is to support .netstd 2.0 to support source generators and to allow removal of EEC_SUPPORT defines by removing std2.0 from core and all libraries.

The changes are mostly restructuring, and thus small but contain some key changes:

- **Status code** struct now comes with a Symbol field, which is used to carry symbols in case the code is not generated.  Currently (until generated) the status code struct must be manually created with a symbol or the ToSymbolicId extension must be called in the core project.  Future will generate Status code constants just like NodeId that contain the symbol which also removes the reflection-based lookup.  Several tests needed to be adjusted as they checked the status code symbol strings instead of the code.
- **Core identifiers** are copied as they were needed for code to compile, that includes attributes, a subset of status codes and node identifiers.  These will never change so no need to generate them.
- The types folder now contains **encoders**, except for json which is still in core.  Once the json encoder is ported to system.text.json it will also be included and Newtonsoft.Json dropped as dependency (-> #3329).  
- Since types relies on **IOperationContext** and **ISystemContext**, and these export IUserIdentity which relies on crypto, these were split and extended in core with ISessionOperationContext and ISessionSystemContext, which mean changes to ServerSystemContext and introduction of SessionOperationContext and SessionSystemContext classes that extend OperationContext and SystemContext.  Some runtime checks in the server are therefore needed to get at the session and auth info, however, those are anyway optional fields and are not on the critical paths, and thus a type check is in order (and was done in the past already, but against OperationContext class).
- **Manifest resources** are now split between Core (nodeset zip, some generated resoures) and Types (built in bsd/xsds).  This needs to be revisited later if the bsd/xsd need to be regenerated during type generation.  Note that the embedded resource names changed as a result. Since these are only used internally and do not constitute public API this feels reasonable vs duplication of resources in 2 assemblies.
- Reflection however now needs to load not just the built in **encodeables** from Opc.Ua.Types assembly, but also the generated encodeables from Opc.Ua.Core assembly.  For this a new helper Utils method was added to get the Core assembly when linked against Opc.Ua.Core otherwise null.
- Whatever utils methods needed to be split out into the new Opc.Ua.Types assembly, they are now in **CoreUtils** static class in Opc.Ua.Types, and Utils.xxxx forwards to them to ensure minimal changes.  Later we would want to obsolete them in favor of CoreUtils, although it might make sense to split them again into domain specific utilities, such as networking, files, etc
2025-11-10 19:33:24 +01:00
Marc Schier e980d825fa Use connect async instead of BeginConnect (#3321)
* Use Connect async in channels
* Add more logging to debug connectivity issues
2025-11-10 15:44:05 +01:00
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