LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Calling LV DLL From .NET 2005 App

I have created a DLL of a Labview 7.1 app which I would like to invoke from a .NET application written in C# from Visual Studio 2005.  I have followed the advise provided by several resources in the NI knowledge base but I always get the following error when attempting to invoke one of the DLL's methods:
"DLL 'C:\Program Files\National Instruments\shared\LabVIEW Run-Time\7.1\DNCompInfo.dll' is 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."
This happens with my application as well as with an example I downloaded from http://sine.ni.com/apps/utf8/niepd_web_display.display_epd4?p_guid=E4C53DA9EB765503E034080020E74861 "Simple Example Using VB.NET to Call LabVIEW DLLs".  The downloaded example was originally created with .NET 2003.  I converted the project to .NET 2005.  Is there something about .NET 2005 that is making this problem occur?
0 Kudos
Message 1 of 7
(4,158 Views)
You're getting extra error detections in VS.NET 2005, which is why you won't see it until VS.NET 2003. However, the problem isn't serious and is actually an issue of using managed C++ (which is what we use in our .NET assemblies). You can ignore it, or upgrade to LV 8, which implemented the workaround recommended by Microsoft (see link).
 
The chance of hitting the loader lock is extremely rare with 7.x, which is why I say you can ignore it. It is also fairly repeatable - if you aren't hanging, it isn't likely to show up on a second run.
Message 2 of 7
(4,151 Views)
If you want to avoid the debugger error message each time you run your program, you can turn the check off:

In Visual Studio go to Debug>>Exceptions... In the Exceptions dialog, expand Managed Debugging Assistants and find LoaderLock. Now uncheck the check box next to LoaderLock.

Next time you run your program that dialog should no longer show up.

(A better solution though is to upgrade LabVIEW as Brian suggests)

Volker
0 Kudos
Message 3 of 7
(4,142 Views)

Thanks for the help!  I had read the MSDN article yesterday and suspected that LV 8 might solve the problem.  I also found that my experiment worked just fine when running outside of the .NET debugging environment.  Volker's suggestion allows me to debug without the exception and that 's good enough for now.

A Little Less Overwhelmed Smiley Wink

0 Kudos
Message 4 of 7
(4,135 Views)

Hi Lycangeek,

 

i have the same problem.I tried to run the example form here:

http://forums.ni.com/ni/board/message?board.id=170&message.id=70372&requireLogin=False , which is also provided through an official ni site.

 

When calling the first pinnvoke'd method, i got the mentioned MDA message.

 

I use Visual Studio 2008 and LabVIEW 8.6 (evaluation version).So, your mentioned improvements in LabVIEW seems currently not to work.

 

Br, Marcel

0 Kudos
Message 5 of 7
(3,723 Views)

Reply to my own message: I now actually rebuilt the DLL with LabVIEW 8.6 and now it works fine.

 

Don't forget to specyfy the answer as reference type in the signature (pointer to value).

 

br, Marcel

0 Kudos
Message 6 of 7
(3,709 Views)

For the record, I just wanted to point out that I've face the same problem with a LabView-7.1-based DLL called from VS Express 2008. 

 

1. Trying to disable the warning as explained above in Debug >> Exceptions >> Managed Debugging Assistants >> LoaderLock did NOT work for me.

2. Using a DLL regenerated with LabView-8.5 solved this problem; the runtime warning disappeared.

 

Cheers!

 

0 Kudos
Message 7 of 7
(3,466 Views)