473,586 Members | 2,863 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 8744
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).
EZNamespaceExte nsions.Net : Develop namespace extensions rapidly in .Net
EZShellExtensio ns.Net : Develop all shell extensions,expl orer bars and BHOs
rapidly in .Net
---------


<aa************ *@gmail.comwrot e in message
news:11******** ************@u3 0g2000hsc.googl egroups.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.co mwrote:
>
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.co mwrote:

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
7147
by: Peter Olcott | last post by:
www.halting-problem.com
28
5194
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(); .... and then call the virtual method, why is it that the base class's method is called instead of the overridden method? How do I fix this if I...
6
3793
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 is more that 1249 bytes, then the progress bar of the browser will move too slow and then displaying that the page not found!!!! If the message is...
16
4889
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 Microsoft must be installed on their servers. Now german Umlaute (ä, ü, ö) and quotes are returned incorrectly in SOAP fault responses. This can be...
0
1209
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 communicate to each other with remoting. I only get this problem if I configure visual studio to start up both exe's for debugging. When I start up...
3
3800
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 ONLY in .NET projects with a mixed win32+.NET dll? 2. How to pass a .NET type to a C++ char ** type? My assumption is this is required unsafe...
1
1392
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 with the service through remoting using the managed interface. Mostly this works ok, but when a call a particular function I get the "loadlock...
3
1145
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
2260
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 the called routine, but I can't modify it. Note that calling this routine from a C++ project does not give off any error. How can I do? Thank...
0
8200
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8338
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7954
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8215
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6610
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3836
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2345
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1448
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.