473,382 Members | 1,583 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

LoaderLock problem

Help me understand this, please.

I have an older VC++ COM DLL that I'm using in a C# project. One of
the COM objects takes a callback object as a parameter so that it can
spin off a thread and do some long running network stuff without
blocking. When I run the application the callback works as expected,
but I get an error when I try to access the COM object in the
callback.

So the call order is: C# app -VC++ COM DLL thread -C# callback ->
COM accessor *boom*

The error I get is:
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 think I understand that this is telling me that the unmanaged VC++
code calling the managed C# code is a no-no. Right? How do I get
around this?

May 29 '07 #1
3 8729
I think I understand that this is telling me that the unmanaged VC++
code calling the managed C# code is a no-no. Right?
That is not the problem. Unmanaged code can call managed code without any
problems.

The problem is that a DLL is executing managed code inside its DLLMain
function and that can *potentially* cause a deadlock situation.

---------
- G Himangi, Sky Software http://www.ssware.com
Shell MegaPack : GUI Controls For Drop-In Windows Explorer like Shell
Browsing Functionality For Your App (.Net & ActiveX Editions).
EZNamespaceExtensions.Net : Develop namespace extensions rapidly in .Net
EZShellExtensions.Net : Develop all shell extensions,explorer bars and BHOs
rapidly in .Net
---------


<aa*************@gmail.comwrote in message
news:11********************@u30g2000hsc.googlegrou ps.com...
Help me understand this, please.

I have an older VC++ COM DLL that I'm using in a C# project. One of
the COM objects takes a callback object as a parameter so that it can
spin off a thread and do some long running network stuff without
blocking. When I run the application the callback works as expected,
but I get an error when I try to access the COM object in the
callback.

So the call order is: C# app -VC++ COM DLL thread -C# callback ->
COM accessor *boom*

The error I get is:
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 think I understand that this is telling me that the unmanaged VC++
code calling the managed C# code is a no-no. Right? How do I get
around this?

May 30 '07 #2
On May 29, 10:40 pm, "G Himangi" <i...@ssware.comwrote:
>
That is not the problem. Unmanaged code can call managed code without any
problems.

The problem is that a DLL is executing managed code inside its DLLMain
function and that can *potentially* cause a deadlock situation.
Hmm... I think the debugger must be getting confused then because
that's definitely not what's going on. This is happening well after
DLLMain is called, and there's no managed code in the DLL or visible
to DLLMain.

I've been suspecting something else is to blame for a bit now since
the blocking version of the method (no callback used) is returning an
object that C# says is invalid. I can't figure out what makes this
call different from all the others that do work just fine.

May 30 '07 #3
Try unchecking the LoaderLock under Debug -Exceptions

It should work.

-VR
"aa*************@gmail.com" wrote:
On May 29, 10:40 pm, "G Himangi" <i...@ssware.comwrote:

That is not the problem. Unmanaged code can call managed code without any
problems.

The problem is that a DLL is executing managed code inside its DLLMain
function and that can *potentially* cause a deadlock situation.

Hmm... I think the debugger must be getting confused then because
that's definitely not what's going on. This is happening well after
DLLMain is called, and there's no managed code in the DLL or visible
to DLLMain.

I've been suspecting something else is to blame for a bit now since
the blocking version of the method (no callback used) is returning an
object that C# says is invalid. I can't figure out what makes this
call different from all the others that do work just fine.

May 30 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

117
by: Peter Olcott | last post by:
www.halting-problem.com
28
by: Jon Davis | last post by:
If I have a class with a virtual method, and a child class that overrides the virtual method, and then I create an instance of the child class AS A base class... BaseClass bc = new ChildClass();...
6
by: Ammar | last post by:
Dear All, I'm facing a small problem. I have a portal web site, that contains articles, for each article, the end user can send a comment about the article. The problem is: I the comment length...
16
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by...
0
by: jnospamster | last post by:
I am getting a LoaderLock message in an application I have written for ..Net 2.0 in C#. It contains only pure managed assemblies. The application consists of 1 dll and 2 .exe projects which...
3
by: Light | last post by:
I've a few questions on platform invoke and some issues I've seen. 1. Is it possible to avoid LoaderLock exception without simply turning it off? Does it occur in .NET projects with win32 dll or...
1
by: ropo | last post by:
I'm using .NET 2.0, I have a manged windows service which uses a mixed C++ assembly. I also have a mangaged dll that defines the interface to the mixed assembly. Another application communicates...
3
by: Ron | last post by:
I have two forms. When I click on new entry I hide current form and show form2 as soon as I click on a textbox in form2 I get a loaderlock error. What is this? How can I get rid of this?
11
by: Beorne | last post by:
I'm trying to call a third party dll routine from C# using pinvoke. Unfortunately I obtain a LoaderLock exception and my application stops. I've seen that it must be some uncorrect behaviour of...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.