简体   繁体   中英

C# Load Assembly on runtime

I have a running appliation which load an Assembly in runtime. I have a folder, which full of .dll files. Whenever a caller make a request, my application will look into a selected dll and load it. Here is snippet of my codes.

if (File.Exists(Path.Combine(assemblySavePath, proxy.AssemblyFileName)))
{
    Assembly = Assembly.LoadFile(Path.Combine(assemblySavePath, proxy.AssemblyFileName));  
    // after this just use it normally
}

Basically whenever a request, I will load it. So my question is, performance wise, is this the correct way? Because I was wondering whether there's a way I could look into memory/GAC/AppDomain first, check whether it existed, without needing me to LoadFile() everytime there's a request.

You should at least have a list which assemblies you already loaded and check that. As you cannot unload an assembly from your AppDomain, you don't have to try to load it again.

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