MDA Loader?

J

Justin Rich

LoaderLock was detected
Message: Attempting managed execution inside OS Loader lock. Do not attempt
to run managed code inside a DllMain or image initialization function since
doing so can cause the application to hang.


I have no idea what its talking about.
it seems to be kicking this off when i do my remote registry read.

Thanks
Justin
 
P

Peter Duniho

Justin said:
LoaderLock was detected
Message: Attempting managed execution inside OS Loader lock. Do not attempt
to run managed code inside a DllMain or image initialization function since
doing so can cause the application to hang.


I have no idea what its talking about.
it seems to be kicking this off when i do my remote registry read.

I don't know what you're using for the remote registry read. If you've
written code yourself that causes managed code to be executed inside the
initialization of a DLL, you may indeed want to heed the warning. There
are ways you can call .NET code that would result in a deadlock.

However, my only actual first-hand experience with this MDA has been
when using Microsoft-provided components that themselves cause the
exception. My assumption (and it is only an assumption :( ) has been
that even though in these cases some managed code is being executed in a
DLL initialization, the authors of that code have avoided (intentionally
or not) calling .NET in a way that would result in deadlock.

You can search this newsgroup (or possibly
microsoft.public.dotnet.framwework...I'm not actually sure which) for
"loaderlock" and find previous messages, including my own, regarding the
topic. The short answer though is that you should try to avoid
executing managed code in a DLL initialization, but if you're not doing
so explicitly yourself you may simply be stuck hoping that the component
you're using and which does do so is doing so safely.

If you can come up with a concise-but-complete example of code that
reproduces the exception, then at least someone might be able to offer
insight as to what component is causing the exception and whether you
can avoid it in any practical way.

Finally, note that the MDA exceptions are part of the debugger. You
should be able to run the application without the debugger without
getting the exceptions. If the MDA is warning of a real problem, that
problem still exists, but otherwise you can safely deploy code that
generates MDA exceptions without worrying about them being set off when
the end user is using the code.

Pete
 
J

Justin Rich

Thanks for the info.
Based on what you have told me it sounds like i have just rely on microsoft
for this one because im not doing anything too crazy. also i only get that
exception every once in a while, its not consistant.. but im using basic
..net stuff in a pretty standard way.

I'll just assume its ok :)

Thanks for the info

Justin
 
P

Peter Duniho

Justin said:
Thanks for the info.
Based on what you have told me it sounds like i have just rely on microsoft
for this one because im not doing anything too crazy. also i only get that
exception every once in a while, its not consistant.. but im using basic
..net stuff in a pretty standard way.

For what it's worth, if you are just using "basic .NET stuff", I don't
think you should ever get that exception.

You should at least explore what in your code is causing it to happen.
It's one thing to know what's going on and accept it, but IMHO it's
quite another to not really know what in your code is causing the
exception and why. The latter is considerable more dangerous, I think,
but it sounds like that's what you're planning to do.

Pete
 
J

Justin Rich

Id love to figure out what is doing it but everytime it tosses the exception
its at a different line.
There are only two things im doing that are sort of out of the norm.

Powershell, which is a RunspaceInvoke, and is pretty much the only way to do
it.
---------------
using (RunspaceInvoke rs = new RunspaceInvoke())
{
Collection<PSObject> results = rs.Invoke(PScommand);
if (results.Count > 0 && results[0] != null)
txthost.Text = results[0].BaseObject.ToString();
}
--------------
and then the remote registry, whiched based on my reading isnt anything too
special.
---------
RegistryKey rkey;
rkey = RegistryKey.OpenRemoteBaseKey(hive, computer).OpenSubKey(path);
if (rkey != null)
thereturn = rkey.GetValue(key).ToString();
else
{
thereturn = "value not found!";
}
--------------
 
P

Peter Duniho

Justin said:
Id love to figure out what is doing it but everytime it tosses the exception
its at a different line.

Did you check every thread in the process? It may be that there's one
thread that is consistently at the same spot each time the exception occurs.
There are only two things im doing that are sort of out of the norm.

Powershell, which is a RunspaceInvoke, and is pretty much the only way to do
it.

Not that I know anything specific about it, but I suspect it's
PowerShell causing the issue. The only reason I say that is that it's
the one thing you've mentioned that involves any sort of non-managed
code. That is, while as near as I can tell PowerShell itself offers a
managed interface, it still has a strong tie to unmanaged code.

Hopefully it falls into that class of "things Microsoft publishes which
set off the LoaderLock MDA, but which don't actually have a problem". :)

If in the future you find your application hanging though, this would be
the first thing I'd revist. :)

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top