給定一個.NET DLL,它由一個類「Place」和一個返回整數的函數「Where」組成;我需要將DLL加載到應用程序域中,執行該功能並卸載應用程序域。執行應用程序域中的函數
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)
此行失敗:
Dim asy As Assembly = domain.Load(buffer)
與此錯誤消息:
'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.'
的文件是在緩衝區中,所以我猜這是一個.dll文件扶養。但是,它應該在基本程序目錄中找到它們。
關於錯誤原因的任何想法?
任何測試的示例代碼用於將程序集加載到AppDomain中,執行函數,然後卸載AppDomain,將不勝感激。
(順便說一句,我用Google搜索,並沒有發現任何有用的樣品)