I am developing all my indicators and strategies outside of NinjaTrader and then copying them as class libraries into ($UserProfile)\Documents\NinjaTrader 8\bin\Custom folder. When I restart the platform then all those assemblies will get successfully loaded and everything works fine. However, NinjaTrader will lock those DLL files and won't allow me to update them without closing the platform. This is expected behavior as Ninja will load those assemblies from files during the startup and lock them for the rest of the application runtime. As you can imagine, the debugging process of those assemblies can be very time-consuming as it needs the platform to be restarted for each build.
I have attempted to create a workaround by enabling shadow copy files, loading the assembly during the runtime, and then adding the assembly to Core.Globals.AssemblyRegistry. See the strategy attached as a reference. Note that we are placing DLL in the lower directory now to avoid NT loading them on the startup from bin\Custom.
using System; using System.Collections.Generic; using System.IO; using System.Reflection; namespace NinjaTrader.NinjaScript.Strategies { public class MyCustomStrategy : Strategy { private readonly HashSet<string> _externalAssemblies = new HashSet<string>(); protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Loads external assemblies during the runtime."; Name = "Assembly Loader"; } else if (State == State.DataLoaded) { if (AppDomain.CurrentDomain.ShadowCopyFiles == false) AppDomain.CurrentDomain.SetShadowCopyFiles(); _externalAssemblies.Clear(); var folderPath = Path.Combine(Environment.GetFolderPath(Environment .SpecialFolder.MyDocuments), @"NinjaTrader 8\bin"); var assemblies = Directory.GetFiles(folderPath, "*.dll"); foreach (var path in assemblies) { var file = new FileInfo(path); var assembly = Assembly.UnsafeLoadFrom(file.FullName); Core.Globals.AssemblyRegistry.Add(file.Name, assembly); _externalAssemblies.Add(file.Name); Print("Added: " + file.Name); } } else if (State == State.Terminated) { foreach (var assembly in _externalAssemblies) { Core.Globals.AssemblyRegistry.Remove(assembly); Print("Removed: " + assembly); } } } } }
Could someone help me fix that or is there any other solution that would make NinjaTrader reload external libraries without restarting the platform every time?
Comment