How to unload an assembly?

pgerard

Newcomer
Joined
Jul 2, 2002
Messages
9
Location
Paris, France
Hello,

I have developped an application which let the user define its own mathematical functions using a subset of VB.Net. I then use Codedom to compile each function into its own assembly. When the user launch a calculation, I load the needed assemblys and use the defined methods.

Everything works fine as long as the user don't try to recompile a function (an assembly) which has been loaded in memory.
I have not been able to find a way to "unload" an Assembly. As of now, the user has to quit the application and relaunch it (not the optimal solution...) .

Does anyone has an idea on how to solve this issue?

Thanks for your help

Pierre

PS : To solve this, the only thing I can think of is to launch another application which would load the assemblies, do the calculations and then communicate the results to the original app, but I have not been able to find any exemple on how to do that so far.
 
I would suggest setting all references to the assembly equal to Nothing, then calling GC.Collect to force the Garbage Collector to clean up.

Let me know how you get on, I'll be needing to do something similar shortly.
 
Oops ... Sorry I pressed enter a bit too fast.

As I was saying, I have been looking into that. Unfortunately, I can't seem to find any exemple in VB which would detail something like that and the documentation... well as usual, it is very good when you know what you are lokking for but as for concepts, it is a bit on the short side.

If you have any link to a good exemple, that would help a lot.

Thanks

Pierre
 
Well, when I was looking through msdn.net, I looked at the
CreateDomain method of the AppDomain class. It seems like
you just declare a variable of type AppDomain and use the
CreateDomain method...
Visual Basic:
Dim myDomain As AppDomain = AppDomain.CreateDomain("NewDomain")
Then I assume all properties and methods of the class would be
available for myDomain, like myDomain.Load(Assemblyname) and
maybe myDomain.ExecuteAssembly("myassembly") or
myDomain.DoCallBack(callbackdelegate)

Here is just a bit of code from MSDN...
Visual Basic:
Public Module PingPong

   Private greetings As String = "PONG!"
   
   Sub Main()
      Dim currentDomain As AppDomain = AppDomain.CurrentDomain
      Dim otherDomain As AppDomain = AppDomain.CreateDomain("otherDomain")
      
      greetings = "PING!"

      MyCallBack()
      otherDomain.DoCallBack(AddressOf MyCallBack)

      ' Output:
      '   PING! from default domain
      '   PONG! from otherDomain
   End Sub 'Main
   
   Sub MyCallBack()
      Dim name As String = AppDomain.CurrentDomain.FriendlyName
      Console.WriteLine(greetings + " from " + name)
   End Sub 'MyCallBack

End Module 'PingPong
And, of course the the Unload method to shut the AppDomain
down (gracefully - must be done executing I believe).
 
Thanks, looks like that was the right path to follow

I have been playing with the domains and it seems to work.

The only remaining problem I seem to have is that when the process in the created appdomain takes too long, I seem somehow to get "disconnected".

I guess it must be due to some Remoting problem between the two appdomain.

I am going to dig into the documentation....

Thanks again

Pierre
 
Back
Top