0

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...

LU RD
  • 34,438
  • 5
  • 88
  • 296
user1009073
  • 3,160
  • 7
  • 40
  • 82

2 Answers2

0

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.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • @@David - Thanks for the idea, but I have tried to be careful with INITIALIZATION routines. I had 2 .pas files with it. One was only declared because I also had a FINALIZATION routine, the other was incredibly trivial. Regardless, I have commented it out. No other INITIALIZATION shows up when I do a global search. Issue still exists. This issue only popped up when I added the REST components, so my next step will probably be to remove them, and see if the error goes away... – user1009073 Sep 05 '16 at 17:19
0

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.

user1009073
  • 3,160
  • 7
  • 40
  • 82