IntelliSense icon indicating copy to clipboard operation
IntelliSense copied to clipboard

Managed Debugging Assistant 'LoaderLock'

Open mvorisek opened this issue 5 years ago • 5 comments

Can the VS warning/exception be properly resolved in the code?

Like http://www.visualstudioextensibility.com/2013/03/17/the-strange-case-of-quot-loaderlock-was-detected-quot-with-a-com-add-in-written-in-net/ here?

mvorisek avatar Mar 28 '19 01:03 mvorisek

The link is not so helpful for what we're doing. We are trying to monitor the process to see when libraries are loaded or unloaded, in order to know when an add-in is loaded into Excel. To do this we use a Windows API called LdrRegisterDllNotification. Since this causes our managed code to run in a potentially dangerous context, Visual Studio is showing the warning. I guess one could create a native code mechanism to track and notify, but would be a fair amount of complication just to avoid the debugging assistant. Better would be a way to run some code (e.g. set an environment variable or registry setting) that disables this particular MDA for this process. Not sure if you know of a way to do that . . .

govert avatar Mar 28 '19 06:03 govert

Enviroment var. https://docs.microsoft.com/en-us/dotnet/framework/debug-trace-profile/diagnosing-errors-with-managed-debugging-assistants#environment-variable or according to this https://github.com/dotnet/docs/blob/master/docs/framework/debug-trace-profile/contextswitchdeadlock-mda.md doc a https://docs.microsoft.com/en-us/dotnet/api/system.mtathreadattribute MTAThreadAttribute attribute should supress the warning.

But the enviroment var. needs to be set before the app. is started and the MTAThreadAttribute attribute can be set only on Main method. Is that possible when this lib. is used as .dll?

mvorisek avatar Mar 28 '19 22:03 mvorisek

@mvorisek - Can you provide an example where did you applied the MTAThreadAttribute ? I do have AutoOpen() method.

eyalmolad avatar Sep 27 '22 09:09 eyalmolad

@mvorisek - Can you provide an example where did you applied the MTAThreadAttribute ? I do have AutoOpen() method.

Thank you for opening this topic, but I am sorry, this issue is 3 years old and I am now working on different projects, thus I cannot provide an example. Hope the description is enough.

mvorisek avatar Sep 27 '22 10:09 mvorisek

@mvorisek Tnx

eyalmolad avatar Sep 27 '22 11:09 eyalmolad