简体   繁体   中英

How load assembly than run some function from it + get result and unload

F# 1.9.9, OS - WinXP I'm trying to do this by two code versions but get errors in both cases.

UPDATE.

dir on "D:\\Sources\\ATProjectChecker\\ATProjectChecker\\tests\\asms" contains FSharp.Core.dll and mscorlib.dll

SerializationException: type is not allowed (my translation from russian)
"TestLoader+cross_dlg@135,ATProjectChecker, Version=0.0.0.0, Culture=neutral,
PublicKeyToken=null".

let load_run_unload path = 
let dlg () : unit = 
    let name = System.Reflection.AssemblyName.GetAssemblyName(path)
    let asm = System.Reflection.Assembly.LoadFile path
    //let asm = System.Reflection.Assembly.ReflectionOnlyLoad(name.FullName)
    //let run = asm.GetType("Test").GetMethod("run")
    //let run () = run.Invoke(null, [||])
    //ignore( run() )
    ()
let dsetup = new System.AppDomainSetup()
dsetup.ApplicationBase <- @"D:\Sources\ATProjectChecker\ATProjectChecker\tests\asms" //__SOURCE_DIRECTORY__
dsetup.ShadowCopyFiles <- "true"

let evil = System.AppDomain.CurrentDomain.Evidence
let tmp_domain = System.AppDomain.CreateDomain("TmpDomain", evil, dsetup)

let cross_dlg = new System.CrossAppDomainDelegate( dlg )
tmp_domain.DoCallBack( cross_dlg )

FileNotFoundException when loading an assembly is thrown in instances where a dependent DLL could not be loaded.

Likely your real problem is one of your dependencies not test .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM