I am trying to create and instantiate a class into a created domain, so that I can unload the domain and replace the class (assembly .dll) while the main application is running, but I can't get it to work for some reason.
Here is the code:
' Create an appdomain
Try
Dim setup As AppDomainSetup = New AppDomainSetup
setup.ApplicationBase = "C:\test"
setup.PrivateBinPath = AppDomain.CurrentDomain.BaseDirectory
setup.ApplicationName = "MyDomain"
appd = AppDomain.CreateDomain("Domain", Nothing, setup)
Catch ex As Exception
MsgBox("Can't create domain: " & ex.Message)
End Try
' Loads an class into the newly created appdomain
Try
Dim test As Object = appd.CreateInstanceFromAndUnwrap("smallclass.dll", "test.SmallClass")
Catch ex As Exception
MsgBox("Can't initiate the class: " & ex.Message)
End Try
The class I am trying to instantiate is in its own solution, and looks like:
Namespace test
Public Class SmallClass
Inherits MarshalByRefObject
Public Sub test()
MsgBox("Test in SmallClass")
End Sub
End Class
End Namespace
Creating the domain works, and the CreateInstanceFromAndUnwrap method finds the DLL, but it can't find the class according to the error message. I don't have any explicit namespace, and the class is called CAPfast, with the correct case. The class also have a public constructor without any arguments.
The error message is in swedish, but here is a translation: It was not possible to load the type test.SmallClass from the assembly SmallClass, Version=1.0.1395.24153, Culture=neutral, PublicKeyToken=null
Anyone have any idea why this isn't working?