Correct, I am using \Drupal::service however I wonder why it is working in one environment and not in another environment. Does it depends on PHP version as well? I am not using hook_install or hook_enable anywhere in custom module.
I have gone through below threads as well.
https://www.drupal.org/project/drupal/issues/3420704
🐛
container not initialized yet
Active
https://www.drupal.org/project/upgrade_status/issues/3221550
🐛
PHP Fatal error: ContainerNotInitializedException thrown while calling __toString on a TranslatableMarkup
Postponed: needs info
#7 says module_load_include()
need to be replaced it with \Drupal::moduleHandler()->loadInclude()
I am trying these solution.
Thanks for the help.
Already search and applied but it didn't helped. Hence created a new issue if I can get any relevant help.
Custom module working as expected in local and other higher environment. @cilefen, have you encountered similar error any time?
poonam11210 → created an issue.