Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom NamespaceUri not available when serializing ExtensionObject #3024

Open
3 of 5 tasks
pzatschl opened this issue Mar 3, 2025 · 5 comments
Open
3 of 5 tasks

Custom NamespaceUri not available when serializing ExtensionObject #3024

pzatschl opened this issue Mar 3, 2025 · 5 comments
Assignees
Labels
bug A bug was identified and should be fixed.

Comments

@pzatschl
Copy link

pzatschl commented Mar 3, 2025

Type of issue

  • Bug
  • Enhancement
  • Compliance
  • Question
  • Help wanted

Current Behavior

When trying to serialize an ExtensionObject to JSON, an Exception is thrown because the corresponding NamespaceURI is not found.

Use case is calling a method with a custom parameter in a KVP array:
Image

When trying to serialize...
Image
...an exception is thrown:
Image

At the same time I don't see any way to configure the context to include my custom namespace.

Line 2881 creation of ExtensionObject:
Image
Already there is only one Namespace present:
Image

Expected Behavior

I would expect for the context at this point to either be configurable or already be containing my custom namespace.
Following the lead of the NamespaceUris being set, one can follow several layers of nesting that amount to setting the value to a string that is hardcoded.

Maybe my approach is wrong altogether?

Steps To Reproduce

OPC_Methoden_Parameter_Test.zip

  1. Open the solution attached to this.
  2. Run the one unit test in debug
  3. Connect via e.g. UaExpert
  4. Open Call Window for the Method on "TestObject"
  5. Add the structured type "CustomType" to at least one of the KVP array elements
  6. Call the Method

Image

Environment

- OS: Windows 11
- Environment: Visual Studio 2022 17.13.0
- Runtime: .NET 6
- Nuget Version: 1.5.375.457
- Component: n/a
- Server: OPCFoundation library based
- Client: UaExpert

Anything else?

No response

@1924006212
Copy link

Image项目报错了看不到信息

@romanett
Copy link
Contributor

romanett commented Mar 5, 2025

@pzatschl I get the Error BadTooManyArguments following your scenario.

Two things i noticed:

  • The Keys of the key vallue pair array are not initialized.

  • You are using JsonConvert.SerialzeObject. I would expect the use of the integrated JsonDecoder/BinaryDecoder

@1924006212
Copy link

How can i create a custom structure Object?

@raserle
Copy link

raserle commented Mar 6, 2025

@romanett

  • BadTooManyArguments is the result of no implementation of method (return base.Call(context, methodToCall, method, result);) This is not the problem, is the result of simplyfying the test solution.

  • The Keys of key value pair are ok, try with strings or empty values will passes the "JsonConvert.SerialzeObject" call

  • Using JsonConvert.SerialzeObject is no problem too, internaly he is using the Opc.Ua.JsonDecoder.

I see a problem in BinaryDecoder on create the ExtensionObject from stream.
On calling method from client, OpcServer is used a coder to translate the call(bytes) in objects and on "Opc.Ua.BinaryDecoder.ReadExtensionObject()" an ExtensionObject is instanziated.
In this chain i missing the correct Context, only a default is set. In this default are no actuall used namespaces. Thats the error we see.

Image

I show you the callstack from BinaryDecoder -> new ExtensionObject();

Opc.Ua.BinaryDecoder
Image

Opc.Ua.ExtensionObject
Image

Opc.Ua.MessageContextExtension
Image

Opc.Ua.ServiceMessageContext
Image
Image
Image

Opc.Ua.NamespaceTable
Image

Possible Solution?

A new constructor in ExtensionObject
Image

and a change in ExtensionObject
Remove this line.
Image

@romanett
Copy link
Contributor

romanett commented Mar 6, 2025

@raserle thanks for the insights. It seems BaseComplexType & Variant could have the same Issue.

@romanett romanett added the bug A bug was identified and should be fixed. label Mar 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug was identified and should be fixed.
Projects
None yet
Development

No branches or pull requests

5 participants