Excel-DNA / IntelliSense

Add in-sheet IntelliSense for Excel UDFs
MIT License
169 stars 52 forks source link

Managed Debugging Assistant 'LoaderLock' #76

Open mvorisek opened 5 years ago

mvorisek commented 5 years ago

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?

govert commented 5 years ago

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

mvorisek commented 5 years ago

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?

eyalmolad commented 2 years ago

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

mvorisek commented 2 years ago

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

eyalmolad commented 2 years ago

@mvorisek Tnx