1

I'm working on a school project which need to be done in Visual Basic. For this I'm porting one of my Python project in this programming language, project which (in Python) is scanning a directory for .py files and then imports them (dynamically) with the __import__ statement, at runtime. It is possible to do this in Visual Basic with .DLL classes?

Thank you

Deanna
  • 23,876
  • 7
  • 71
  • 156
ov1d1u
  • 958
  • 1
  • 17
  • 38

1 Answers1

1

You can load assemblies dynamically using Assembly.LoadFrom(fileName) and then get the assembly information, enumerate the types, create instance of those types, etc. The details depend on what exactly you want this DLLs for.

When you have the Type for the object you want to create, you can use code similar to this that uses Activator.CreateInstance() method.

You can find some (C#) samples in one of my projects: http://code.earlsoft.co.uk/hg/builderpro/file/41046067e90e/Library/Extensions/Extension.cs http://code.earlsoft.co.uk/hg/builderpro/file/41046067e90e/Library/ActionInfo/ActionInfo.cs

Community
  • 1
  • 1
Deanna
  • 23,876
  • 7
  • 71
  • 156
  • So, if I have a class "DummyPlugin" in DLL, how I create an instance of it in my Main Application? Sorry if this it's a dumb question, but I'm very newbie in VB.Net and all this Microsoft stuff... – ov1d1u May 03 '12 at 15:29
  • I've added a bit on calling Activator.CreateInstance. – Deanna May 03 '12 at 16:15
  • Oh, sorry :) Yout information was helpful, leading me to find the solution for my question. Currently I'm on Linux, but I'll post more details after I'll continue working on this project. Anyway, thank you a lot! – ov1d1u May 14 '12 at 18:10