Question

I have the following code that loads a dll file and creates a new type based on the content of the dll file :

    Dim Assembly As Assembly = Assembly.LoadFrom("C:\Test.dll")

    AppDomain.CurrentDomain.Load(Assembly.GetName())
    Dim ClassType As Type = Assembly.GetType("Test.ClassTest")

    'This line doesn't compile
    Dim Instance As ClassType

The type ClassType is created successfullly but I'm unable to instanciate it or use it in the last line.

Does anyone know how to instanciate a new type created during run time ?

Thank you in advance.

Was it helpful?

Solution

Solution :

    Dim Assembly As Assembly = Assembly.LoadFrom("C:\Test.dll")

    AppDomain.CurrentDomain.Load(Assembly.GetName())
    Dim ClassType As Type = Assembly.GetType("Test.ClassTest")

    Dim Instance = Activator.CreateInstance(ClassType)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top