BadInvalidState
BadState machines
BadInvalidState means the request was well formed but the target is not in a state that permits it right now. It is normally a state machine, a file handle or a session lifecycle refusing an out-of-order operation, so read the current state and drive the transition first.
What you actually see
The same call succeeds sometimes and fails at other times, with the difference tracking what the machine or the object was doing at that moment.
Why it happens
- A state machine transition that is not allowed from the current statePart 16 state machines expose CurrentState and LastTransition and only accept the transitions their model defines. Calling start on a machine already executing, or resume on one that was never suspended, is refused here. PackML and the machine-tool production state machines behave the same way.
- File transfer operations out of orderPart 20 file objects require open before read or write, and a valid file handle for each operation. Reading with a stale handle, or after a close, fails on state rather than on arguments.
- A session or subscription used before it is readyOperations issued on a session that has not been activated, or on a subscription whose publishing has been disabled, are refused on state. Reconnect logic that resumes work before ActivateSession completes is the usual mechanism.
- A device in maintenance or out of serviceWhere a machinery item is in a maintenance or out-of-service state, writes and methods that would change production behaviour are refused deliberately. This is correct behaviour and should be surfaced to the operator, not retried.
- A concurrent client changed the state between your read and your callYou read a permitting state, another client acted, and your call arrives against the new state. On a busy machine this is common and is the reason state checks must be treated as advisory rather than as a guarantee.
How to fix it
In diagnostic order: work down, do not skip ahead.
- Read the current state before actingBrowse the owning object for its state machine and read CurrentState. For a file object, check whether you hold a valid open handle. Knowing the state turns the failure into a decision rather than a retry.
- Consult the model for the legal transitionsThe companion specification or the vendor documentation defines which transitions are valid from which state. Issue the intermediate transition first rather than repeating the one that failed.
- Subscribe to the state instead of pollingCreate a MonitoredItem on CurrentState, and subscribe to the transition events where the model provides them. Act when the state permits it rather than retrying on a timer.
- Fix the ordering in reconnect logicEnsure the client completes ActivateSession, and either TransferSubscriptions or a fresh CreateSubscription, before it issues any operational request. Queue application work until the session is genuinely usable.
- Handle concurrency explicitlyAccept that a state read can be stale, retry once after re-reading the state, and if the state is now legitimately different, surface it to the operator rather than looping.
Where it shows up, by tool and stack
| Tool / stack | What to do there |
|---|---|
| UaExpert | Browse the object for a CurrentState variable and add it to a data access view next to the method you are calling. Watching both together makes the allowed transitions obvious in a few minutes. |
| asyncua (Python) | Read CurrentState and its Id property rather than only the display text, since the localised text differs between servers while the state NodeId does not. |
| node-opcua | The file transfer client helpers enforce open, read or write, and close ordering. Hand-rolled file operations are where the handle-related version of this code usually appears. |
| UA-.NETStandard (C#) | SessionReconnectHandler restores the session before application code resumes. Issuing requests from a separate thread during reconnect is a common way to hit this. |
| Ignition | Scripted method calls fired from a tag change event can arrive during a state transition. Gate them on the machine state tag and let the failure surface to the operator rather than retrying. |
| Beckhoff TwinCAT | Methods and writes against a PLC task that is not running are refused on state. Check the task run state before concluding there is an address space problem. |
What it looks like in the log
Call rejected: BadInvalidState (CurrentState=Suspended, transition requires Executing)
File read failed: invalid file handle or file not open
Request issued before session activation completed
Confirm the fix
Read the state, perform the legal transition, confirm CurrentState changed, then issue the original operation and check it returns good and the machine reflects the change.
Stop it happening again
Model the state machine in the client, subscribe to CurrentState and transition events, and order reconnect steps so no operational request can be issued before the session is fully activated.
Stuck on more than one of these? The troubleshooting clinic works through broken configurations end to end, on camera.
Troubleshooting clinic →Last verified 7 September 2026 against OPC UA 1.05.07. OPC UA Connect is an educational resource and is not affiliated with the OPC Foundation.