views:

469

answers:

1

Given a .NET DLL that consists of a class "Place" and a function "Where" that returns an integer; I need to load the dll into an application domain, execute the function and unload the application domain.


Dim domain As AppDomain = AppDomain.CreateDomain("Executor")            
Dim buffer() As Byte = IO.File.ReadAllBytes("c:\path\Locator.dll")
Dim asy As Assembly = domain.Load(buffer)
Dim obj As [Object] = asy.CreateInstance("Locator.Place")
Dim method As MethodInfo = obj.GetType.GetMethod("Where")
Dim result as Integer = method.Invoke(obj, New [Object]() { 1 })
AppDomain.Unload(domain)

This line fails:


Dim asy As Assembly = domain.Load(buffer)

With this error message:


'Could not load file or assembly 'Place, Version=1.0.0.0, Culture=neutral, PublicKeyToken-null' or one of it's dependencies.  The System Cannot find the specified file.'

The file is in the buffer, so I'm guessing it's a dependancy .dll. However, it should find those in the base program directory.

Any ideas as to the cause of the error?

Any tested sample code for loading an assembly into an AppDomain, Execting a function, then unloading the AppDomain would be appreciated.

(BTW, I have googled and have not found any useful samples.)

A: 

If you want to know what dependency could not be loaded, try using fuslogvw. Check http://msdn.microsoft.com/en-us/library/e74a18c4(VS.71).aspx

I found the explanation on link text pretty good. It illustrates some pitfalls and provides sample code that should be easily translated into VB.NET.

I hope this helps.

Renze.

Renze de Waal