# system.opcua.callMethod throws ClassCastException when invoking with arguments

**URL:** <https://forum.inductiveautomation.com/t/system-opcua-callmethod-throws-classcastexception-when-invoking-with-arguments/87964>\
**Category:** Ignition\
**Tags:** ignition81, scripting\
**Created:** [March 27, 2024, 1:21pm UTC](https://forum.inductiveautomation.com/t/system-opcua-callmethod-throws-classcastexception-when-invoking-with-arguments/87964 "2024-03-27T13:21:49Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Toni\_Kaufmann](https://avatars.discourse-cdn.com/v4/letter/t/df788c/32.png) [@Toni\_Kaufmann](https://forum.inductiveautomation.com/u/Toni_Kaufmann)\
**Post date:** [March 27, 2024, 1:21pm UTC](https://forum.inductiveautomation.com/t/system-opcua-callmethod-throws-classcastexception-when-invoking-with-arguments/87964/1 "2024-03-27T13:21:49Z")

</div>

Hi, calling a OPCUA method with two InputArguments (ua:String, ua:Int32) does not work. I get a ClassCastException.

result = system.opcua.callMethod("RobotArm", "ns=4;i=532", "ns=4;i=650", ["myArticleId", 100])

java.lang.ClassCastException: java.lang.ClassCastException: class org.eclipse.milo.opcua.sdk.client.nodes.UaVariableNode cannot be cast to class

When calling a method without any InputArguments it works fine:  
result = system.opcua.callMethod("RobotArm", "ns=4;i=532", "ns=4;i=653", )

I also turned on the system.opcua.callMethod DEBUG logger. No helpful hints.  
Trying to json encode the arguments didn't help either.

The gateway runs on a M1 Mac.

Thanks a lot for help! Toni

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 27, 2024, 1:24pm UTC](https://forum.inductiveautomation.com/t/system-opcua-callmethod-throws-classcastexception-when-invoking-with-arguments/87964/2 "2024-03-27T13:24:38Z")

</div>

> [@Toni\_Kaufmann](#):
>
> java.lang.ClassCastException: java.lang.ClassCastException: class org.eclipse.milo.opcua.sdk.client.nodes.UaVariableNode cannot be cast to class

Hmm, this hints at a perhaps a data modelling problem in the underlying server...

Any chance you can make this OPC UA connection without security and get a Wireshark capture while you call this method? What server is this?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 27, 2024, 1:30pm UTC](https://forum.inductiveautomation.com/t/system-opcua-callmethod-throws-classcastexception-when-invoking-with-arguments/87964/3 "2024-03-27T13:30:28Z")

</div>

It would also be useful if you could provide the _full_ error and stack trace from the logs.

---

<div class="post-metadata">

**Author:** ![Toni\_Kaufmann](https://avatars.discourse-cdn.com/v4/letter/t/df788c/32.png) [@Toni\_Kaufmann](https://forum.inductiveautomation.com/u/Toni_Kaufmann)\
**Post date:** [March 27, 2024, 1:30pm UTC](https://forum.inductiveautomation.com/t/system-opcua-callmethod-throws-classcastexception-when-invoking-with-arguments/87964/4 "2024-03-27T13:30:38Z")

</div>

I'm using the the opcua-asyncio ([GitHub - FreeOpcUa/opcua-asyncio: OPC UA library for python \>= 3.7](https://github.com/FreeOpcUa/opcua-asyncio)) server. I can invoke the method with the two input arguments with the Prosys OPC UA Browser successfully.

So far I connect to the server without security. So network tracing should be possible.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 27, 2024, 1:32pm UTC](https://forum.inductiveautomation.com/t/system-opcua-callmethod-throws-classcastexception-when-invoking-with-arguments/87964/5 "2024-03-27T13:32:13Z")

</div>

Oh... I don't expect this to work then. Both of those Python OPC UA implementations are [broken](https://forum.inductiveautomation.com/t/error-calling-opc-ua-method/83234) and they don't seem to care or respond to my bug reports.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 27, 2024, 1:34pm UTC](https://forum.inductiveautomation.com/t/system-opcua-callmethod-throws-classcastexception-when-invoking-with-arguments/87964/6 "2024-03-27T13:34:56Z")

</div>

At some point I will rewrite the logic in `system.opcua.callMethod` that triggers this bug in the Python servers, but it's not a priority right now with all the other work we have going on. It's not a super trivial change.

---

<div class="post-metadata">

**Author:** ![Toni\_Kaufmann](https://avatars.discourse-cdn.com/v4/letter/t/df788c/32.png) [@Toni\_Kaufmann](https://forum.inductiveautomation.com/u/Toni_Kaufmann)\
**Post date:** [March 27, 2024, 1:35pm UTC](https://forum.inductiveautomation.com/t/system-opcua-callmethod-throws-classcastexception-when-invoking-with-arguments/87964/7 "2024-03-27T13:35:49Z")

</div>

I see. Well, I guess I have to switch to another OPC UA SDK. Thanks anyway.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 27, 2024, 1:36pm UTC](https://forum.inductiveautomation.com/t/system-opcua-callmethod-throws-classcastexception-when-invoking-with-arguments/87964/8 "2024-03-27T13:36:04Z")

</div>

My last post in the thread I linked to has some suggestions.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [September 12, 2024, 12:25am UTC](https://forum.inductiveautomation.com/t/system-opcua-callmethod-throws-classcastexception-when-invoking-with-arguments/87964/9 "2024-09-12T00:25:11Z")

</div>

The implementation of `system.opcua.callMethod` was refactored in Ignition 8.1.43 to work around this bug in FreeOpcUa-based servers.

---

<div class="post-metadata">

**Author:** ![JantjeBeton](https://avatars.discourse-cdn.com/v4/letter/j/ea666f/32.png) [@JantjeBeton](https://forum.inductiveautomation.com/u/JantjeBeton)\
**Post date:** [March 20, 2025, 8:07pm UTC](https://forum.inductiveautomation.com/t/system-opcua-callmethod-throws-classcastexception-when-invoking-with-arguments/87964/10 "2025-03-20T20:07:04Z")

</div>

Hi Kevin,

I wonder what I'm doing wrong.  
I've copied the example form the manual for the copua.callMethod and I get the following response:

```python

|cwdLogger|20Mar2025 20:59:10|MOBZ.DAL.Msbs.mcSample() output values from the callt: [].|
|cwdLogger|20Mar2025 20:59:10|MOBZ.DAL.Msbs.mcSample() list of StatusCodes, one for each input argument: [].|
|cwdLogger|20Mar2025 20:59:10|MOBZ.DAL.Msbs.mcSample() StatusCode for the call: (2150105088L, u'Bad_SubscriptionIdInvalid', u'The subscription id is not valid.').|

```

The code is below, executed on the gateway using a tag-change script:

```python
def mcSample():
	
	cwdLogging.wrapLog(cwdLogging.logNaam, ("MOBZ.DAL.Msbs.mcSample()" %()), 2)
	
	# Call the Server object's GetMonitoredItems method.
	result = system.opcua.callMethod(
        "Ignition OPC UA Server",
        "ns=0;i=2253",
        "ns=0;i=11492",
        [1]
    )
 
	# Below we print the various elements in the results. The print statements could easily be replaced by something more useful.
	
	# Prints the StatusCode for the call.
	cwdLogging.wrapLog(cwdLogging.logNaam, ("MOBZ.DAL.Msbs.mcSample() StatusCode for the call: %s." %( str(result[0])) ), 2)
	
	# Prints the list of StatusCodes, one for each input argument passed to system.opcua.callMethod.
	cwdLogging.wrapLog(cwdLogging.logNaam, ("MOBZ.DAL.Msbs.mcSample() list of StatusCodes, one for each input argument: %s." %( result[1]) ), 2)
	 
	# Prints the output values from the call.
	cwdLogging.wrapLog(cwdLogging.logNaam, ("MOBZ.DAL.Msbs.mcSample() output values from the callt: %s." %( result[2])), 2)

```

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 20, 2025, 8:09pm UTC](https://forum.inductiveautomation.com/t/system-opcua-callmethod-throws-classcastexception-when-invoking-with-arguments/87964/11 "2025-03-20T20:09:11Z")

</div>

You're calling a standard method in the OPC UA server called GetMonitoredItems and passing a subscription id that doesn't exist, according to the results.

What are you expecting to happen? Are you just trying to get this working before you call a method on some other server?
