Delphi - OS Loader Lock issue suddenly appearing with Excel

195 Views Asked by At

I am working on a Delphi plugin for Excel. It also uses the AddIn Express COM Library (excellent BTW). The code had been working fine. I have added another Ribbon menu option, which calls a new form. This form has the REST controls (Client, Response, etc.). While the components are tied to each other, they do not have information about URLs. This is set at runtime. I compile my project.

  • If I run it standalone (outside of debugger), it runs fine. It sets the URL resources, calls the REST service, and displays data in a memo.
  • If I run it from within Delphi, I immediately get dumped into assembly code, and I get the error message in the Event Log

    “Attempting managed execution inside OS Loader Lock. Do not attempt to run managed code inside a DllMain or image initiations function since doing so can cause the application to hang.”

This used to run fine, but I have just added a form (specifically, I added a parent form, with REST components, a RestAdapter, TDatasource and ClientDataSet, and inherited from it). In Googling, it appears that this is a debugger issue, and that (at least in Visual Studio), this can be turned off via Exceptions / Ignore Loader Lock. I cannot find any similar functionality within the Delphi (Seattle) debugger.

I have run AddIn express without issues, my plugin used to run without issue, and I have run standalone REST demo apps without issues. Is it possible that the combination is causing this problem? Any idea how to disable the debugger checking for Loader Lock? If it helps any, the last message PRIOR to the “OS Loader Lock” message in the event log shows that module: CSCAPI.dll was loaded. I am wondering if I need to dynamically create the REST components. My suspicion is that these components are created when the app (aka Excel with my plugin) starts, and something is being initialized in a way that is making the debugger upset...

2

There are 2 best solutions below

0
On BEST ANSWER

I finally solved what was happening. I had purchased and installed another Excel plugin. It was that which was causing my issue. Apparently it uses code within it's initialization routine which was causing my issue. Once I set that plugin to inactive, my code works fine. It wasn't an issue with the REST components at all.

1
On

The likely explanation is that some code in one of your initialization units is responsible. This code is called from the DllMain function. Attempting managed execution from DllMain is indeed asking for trouble.

In my AddInExpress module all initialization sections are empty. Any initialization is performed elsewhere. I know that will seem frustrating to contemplate but you really must not do anything remotely complex in your DllMain.

I suggest your next move is to remove code until you find which initialization section is responsible. Note that any units in your project could be responsible, even Embarcadero library code such as the Embarcadero REST components that you use. That's your starting point. As for the solution well consider that once you've isolated the problem.