Are there any hot-swap implementations in .NET?

I am looking for a good hot swap implementation in .NET. I need things:

  • The ability to deploy DLLs in a specific folder and start the system.
  • After starting the current system, update the corresponding links in the container.

I searched for MEF and its directory loading mechanism, but it seems very unreliable. Maybe someone out there has an alternative implementation?

+5
source share
1 answer

AssemblyResolve, newAppDomain() . , AppDomain . loadFromAppDomain(), . dll C:\dlls . ( , VB # .)

String dllFolder = "C:\\dlls";

public void newAppDomain()
{
    AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(assemblyResolve);
}

private static Assembly assemblyResolve(Object sender, ResolveEventArgs args){
    String assemblyPath = Path.Combine(dllFolder, new AssemblyName(args.Name).Name + ".dll");
    if(!File.Exists(assemblyPath))
    {
        return null;
    }
    else
    {
        return Assembly.LoadFrom(assemblyPath);
    }
}

private Type loadFromAppDomain(String className)
{
    Assembly[] asses = AppDomain.CurrentDomain.GetAssemblies();
    List<Type> types = new List<Type>();
    foreach(Assembly ass in asses)
    {
        Type t = ass.GetType(className);
        if(t != null) types.Add(t);
    }
    if(types.Count == 1)
        return types.First();
    else
        return null;
}
+6

All Articles