I'm looking for a good implementation of hot-swapping done in .NET. The things I need are:
I've been looking into MEF and its directory loading mechanism, but it seems very unreliable. Maybe someone out there has an alternative implementation?
Hot swappable components include network adapters, Universal Serial Bus (USB) devices (like a keyboard) and external hard drives, among others. Hot swap is a required feature in fault-tolerant systems with redundant components such as circuit boards, hard drives, etc.
Hot swap controllers provides circuit protection from many potential hazards caused by abrupt changes in the power supply. This type of IC can monitor overvoltage and undervoltage conditions and open and close switches very quickly to protect sensitive circuits when an unsafe power condition is detected.
Hot pluggable power supply units (PSUs) can be removed and installed while the server is running without affecting the rest of the server's capabilities. Hot plugging or hot swapping gets its name because devices are swapped while a computer is running - or hot.
Hotswap (also hot-swap or hot swap) is an acclaimed feature that Kono Store and Input Club adopted early. It describes keyboards that allow switch replacement without soldering. Kaihua (Kailh), a premier switch manufacturer in China, created the market-dominating hotswap socket design pictured below.
You can provide a custom event handler for AssemblyResolve
by calling newAppDomain()
below. Supply your directory so AppDomain
looks there. When loading a Type, use function loadFromAppDomain()
to return it. This should allow you to copy new dlls to C:\dlls
at runtime and reload from there. (Forgive me, I translated this from my VB source to C# according to your tag.)
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With