1

I have 2 files: lib.dll & executor.exe.

lib.dll

Public Module Module1
   Public Function Abc()
      MsgBox("I am dll")
   End Function
End Module

I want to import lib.dll and use its function in executor.exe.
I know lib.dll can be added via visual basic reference,
But when I place lib.dll in another directory, then it shows errors.
I want to import dll from a path something like as shown below.

imports "C:\Users\root\Desktop\lib.dll"
Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
       Module1.Abc()
    End Sub
End Class
Sorry IwontTell
  • 466
  • 10
  • 29
  • 1
    [How to call a method located inside a C# DLL, from VB.Net, with late binding](https://stackoverflow.com/questions/10450935/how-to-call-a-method-located-inside-a-c-sharp-dll-from-vb-net-with-late-bindin) –  Dec 01 '19 at 09:54
  • @JQSOFT thanks but this link didn't solved my problem. – Sorry IwontTell Dec 01 '19 at 10:17
  • https://stackoverflow.com/questions/1373100/how-to-add-folder-to-assembly-search-path-at-runtime-in-net – jmcilhinney Dec 01 '19 at 10:20
  • @jmcilhinney thanks but I was asking for vb.net (visual basic) code, NOT C#. – Sorry IwontTell Dec 01 '19 at 10:22
  • Create a new `Class` with a proper name, move the method to the new class, change the `Function` to a public `Sub` since it returns nothing, and try again the same link and do the necessary changes. –  Dec 01 '19 at 10:29
  • Do you pass the right path of your `DLL` file? the second link by _jmcilhinney_ shows you how. Not so hard to extract the idea from c# code. –  Dec 01 '19 at 10:41
  • @JQSOFT sir as you said:
    create class
    change function to sub
    I got this but it doesn't return anything `Imports System.Reflection Public Class Form1 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Try Dim ass As Assembly = Assembly.LoadFrom("C:\Users\root\source\repos\ClassLibrary1\bin\Debug\ClassLibrary1.dll") Dim obj As Object = ass.CreateInstance("test()", True) Catch ex As Exception MessageBox.Show(ex.Message) End Try End Sub End Class `
    – Sorry IwontTell Dec 01 '19 at 10:50
  • 1
    Try: go to the `EXE` folder and run it as Administrator. Could be a security issue. Also you can edit your post to add what you've tried. Hard to read the code from comments. –  Dec 01 '19 at 11:04

1 Answers1

3

You can specify folder where runtime will search for DLLs in .config file using "probing" element.

https://learn.microsoft.com/en-us/dotnet/framework/configure-apps/specify-assembly-location

Ondřej
  • 1,645
  • 1
  • 18
  • 29
  • this answer is somewhere according to my point that we should able to use **DLL** from a path, But in my **XML** file, I didn't find any **DLL** path. – Sorry IwontTell Dec 02 '19 at 14:52
  • You did not read that MSDN documentation correctly. It is NOT path to DLL file, but path to folder, where DLL files are. .NET Framework will try to find referenced DLLs in this folder(s). – Ondřej Dec 04 '19 at 10:42