Page MenuHomePhabricator

Dll Loading Error in Microservices using a Service in a Service
Closed, ResolvedPublic

Description

When implementing a Microservice that itself access a Microservice internally in it's constructor windows will fail loading the dll/module.
E.g. a Microservice implementation uses the PythonService in it's implementation. If the service accesses the other service in it's constructor the dll will fail to load if 2 different services from different modules are accessed at the same time in the activator.

Code Example:
The Constructor of a service executes:

us::ModuleContext* context = us::GetModuleContext();
m_PythonServiceRef = context->GetServiceReference<mitk::IPythonService>();
m_PythonService = dynamic_cast<mitk::PythonService*> (
      context->GetService<mitk::IPythonService>(m_PythonServiceRef)
      );

Event Timeline

Can you give more details why this is supposed to be a bug in the MITK Core?

Is the constructor code executed? Does the dynamic_cast work? Does it throw exceptions?

BTW, by using "interface classes" you should never down-cast an "interface pointer" to a concrete implementation.

The context->GetService<mitk::IPythonService>(m_PythonServiceRef) call fails with the exception: "Default constructed ServiceReference is not a valid input to GetService()". The same code works without any problems on unix.

Well, the message is saying it all. You allways need to check if the service reference is valid.

Linkers on different platforms behave different. The Windows linker probably does not generate a link dependency on your python module which registers the python service. This is actually a good thing. You should not link to the module implementing the service (except this module also provides the interface class). And you should be able to cope with non-existing service instances.

User heime has pushed new remote branch:

bug-18769-python-service-load

User heime has pushed new remote branch:

bug-18769-python-service-load2