LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I get my exe to load a .NET dll from a different location

I have a series of .NET assemblies. They are installed on my target and my development machine in the same location. When
I build my exe and run it, I want it to look for those assemblies in this location, not in the /app/Data/ directory. Is this possible?
0 Kudos
Message 1 of 5
(4,054 Views)
Ok, I've got a funky workaround but I'd still like to know if there's a more direct way of doing this. On both my target and development systems, I've got my DLLs in C:\path\abc\ . Now, at one point I thought I could just set my support directory in the build spec to this path and the builder would recognize the assemblies were there and keep going. It actually tried to copy the assembles to the directory where they were already located and the expected error was generated. So, what I've done is, on my development machine I rename C:\path\abc to C:\path\def, then create an empty folder C:\path\abc, open the VI and point it to the new location of my assemblies, set the support directory in the build spec to point to C:\path\abc\ and build. Then I can just copy my exe to the target machine and it sees all my DLLs
0 Kudos
Message 2 of 5
(4,043 Views)
Hi ayd,lfud,

When you build your VIs into an executable and those VIs happen to reference .NET assemblies, then you must obey the rules of .NET and understand how the .NET CLR locates assemblies.  .NET requires that all assemblies either live in the GAC or in the same directory, or subdirectory of the application. These requirement are based upon the fact of how the .NET CLR attempts to locate assemblies. I could go into detail about how .NET probes for assemblies, but it’s better if you take a look at Microsoft documents such as the MSDN article How the Runtime Locates Assemblies.

Anyway, with regards to LabVIEW, if you build some LabVIEW application called blah.exe, then the .NET assemblies it needs must either be in the GAC or in the same directory or subdirectory of blah.exe.

You need to consider these rules when configuring your applications properties. One suggestion is to add all your .NET assemblies to your LabVIEW project and make sure to copy them over into the data directory which is in a subdirectory of the application.exe directory. In this case, the .NET CLR will find those assemblies. Plus adding these assemblies to your project and setting them to copy over makes your life easier. This way you don't have to manually copy and paste your assemblies to some directory in your applications directory.

Hope this helps!

Best Regards,
Jonathan N.
National Instruments
0 Kudos
Message 3 of 5
(4,022 Views)

Hi Jonathan !

Thanks for these explanations and links... but you said that all .NET assemblies must be in the  same directory or subdirectory as the application. That's why placing a .NET dll in the support directory (data) works... In my case, my .NET assemblies are placed in a application's subdirectory named "Lib", so at the same 'level' as "data" directory...

Nevertheless, if I build my executable placing these Dlls in the "Lib" folder, then an explorer window appears when launching the exe and asking for Dlls.

But if build my executable placing the Dlls in the "data" folder they are automatically found...

 

Why is that ? 

CLA, CTA, LV Champion
View Cyril Gambini's profile on LinkedIn
This post is made under CC BY 4.0 DEED licensing
0 Kudos
Message 4 of 5
(3,819 Views)

Hi there

 

Check the "Support Directory" Setting on the "Destinations" of the Applications Build Specification. This defaults to "Application\data".

Best regards
chris

CL(A)Dly bending G-Force with LabVIEW

famous last words: "oh my god, it is full of stars!"
Message 5 of 5
(3,814 Views)