MES Object Manager | Attempt to read the MES object manager before it has been assigned

Problem

com.inductiveautomation.ignition.client.gateway_interface.GatewayException: com.inductiveautomation.ignition.client.gateway_interface.GatewayException: 
Attempt to read the MES object manager before it has been assigned.
caused by GatewayException: Attempt to read the MES object manager before it has been assigned.
caused by Error: Attempt to read the MES object manager before it has been assigned.

Solution

That exception happens when the Manager is not started. Things that can cause that:

1) calling too early 

2) if the module is in trial on startup we do not start some managers

3) an exception happened in initializing and the manager did not start => check the logs

If you have Gateway startup or timer scripts calling mes functions, try introducing logic to determine if the production module has been started:

system.mes.isProductionStarted

Python
if system.mes.isProductionStarted():
#call your scripts
pass