VB.NET - Set path for DLLs

  • Thread starter Thread starter Max
  • Start date Start date
M

Max

Have a little problem here; I have a solution with two projects. One of
the projects is an executable file and the other is a dll. The dll is
just basically one class, so in the exe I've added that project as a
reference and am able to use all the contents by creating a new object
(Dim myclass as new dll_file.myclass). That works fine, when I build the
solution it creates those two files and everything works, however, what
I need to do is have the dll in a different folder then the executable.
How do I tell the exe file to look for this dll in the \bin\ folder for
example? Right now I've specified the target paths so it automatically
puts the files where they need to be, but when I launch the program it
comes up with an error that basically states file not found.
 
Max said:
Have a little problem here; I have a solution with two projects. One
of the projects is an executable file and the other is a dll. The
dll is just basically one class, so in the exe I've added that
project as a reference and am able to use all the contents by
creating a new object (Dim myclass as new dll_file.myclass). That
works fine, when I build the solution it creates those two files and
everything works, however, what I need to do is have the dll in a
different folder then the executable. How do I tell the exe file to
look for this dll in the \bin\ folder for example? Right now I've
specified the target paths so it automatically puts the files where
they need to be, but when I launch the program it comes up with an
error that basically states file not found.



Maybe this helps?

http://msdn.microsoft.com/library/en-us/cpguide/html/cpconhowruntimelocatesassemblies.asp


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
Max,
In addition to Armin's comments.

You can use either AppDomain.AppendPrivatePath or the
runtime/assemblyBinding/probing/privatePath app.config setting.

The problem with AppDomain.AppendPrivatePath, is it gets done after the
startup class & method starts, so if the startup class & method refers to
anything in the class assemblies you get JIT errors...

Public Sub Main()
AppDomain.CurrentDomain.AppendPRivatePath("bin")
...
End Sub

<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="bin" />
</assemblyBinding>
</runtime>
</configuration>

Hope this helps
Jay
 
Thanks for that suggestion, however I'm not exactly sure how to use that
<configuration> stuff?
I tried AppDomain way, but still doesn't seem to find the dll:

Public Sub Main()
AppDomain.CurrentDomain.AppendPrivatePath("bin")

Dim Shell As New Shell_dll.Shell_Main
Shell.TestSub()
End Sub

Basically have Shell_dll namespace and a class Shell_Main in the
Shell.dll file that's in \bin directory. TestSub should simply give me a
msgbox to let me know that it works.
 
Max,
To use the <configuration> stuff you need to add an app.config to your EXE
project, the "best" way to do this is to use "Project - Add New Item -
Application Configuration File". This will create an empty app.config file
in the root of your project.

After you do this, when you build your app a file will be created in your
bin directory called YourProject.exe.config (that matches your
YouProject.exe).

Hope this helps
Jay
 
Back
Top