Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Dynamic load of class outside of .dll fails

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Dynamic load of class outside of .dll fails

    I want to dynamically load a class that is outside of my assembly and is not in another assembly, it is compiled locally on the machine.

    It appears that the code inside one dll cannot load a class from outside of it's own dll.

    To demonstrate the problem I included the two source files and the assembly.

    The indicator is called TestLoader, which dynamically loads a class called "MyNamespace.MyClassName" using the lines:

    Code:
    string cls = "MyNameSpace.MyClassName";
    Type t = Type.GetType(cls , true, false);
    SimpleInterface customClass;
    				
    if (t != null)
    {
        customClass = (SimpleInterface)Activator.CreateInstance(t);
        Print(Name + " SUCCESS! loaded: " + customClass.getName());
    }
    When I do a basic compile on the two source files, put Testloader on a chart, it works as expected.

    However, when I do these steps it does NOT work:
    -Build the assembly and install it into Ninja on a different machine.
    -Copy the source code for MyClassName to that machine and compile.
    -Put TestLoader on a chart and run it. The output window shows it does not work.

    Is there a way to make ninja build the assembly so it can load that class?
    What can I do to make that class dynamically loaded?
    Is there a different windows call that would find the class outside the dll?

    See attached assembly and source files for example.

    BTW, The reason for this code is to allow a bit of customization by user of assembly.

    Thanks,
    Gary
    Attached Files

    #2
    It is my understanding that you would need to include the custom class with your TestLoader assembly. Otherwise TestLoader will only be able to access classes that come natively with NinjaTrader.

    I do not know any workaround for this limitation, but would be interested in finding a solution.

    Comment


      #3
      Originally posted by Harry View Post
      It is my understanding that you would need to include the custom class with your TestLoader assembly. Otherwise TestLoader will only be able to access classes that come natively with NinjaTrader.

      I do not know any workaround for this limitation, but would be interested in finding a solution.
      Actually, even that is not quite correct. The class must be included when the assembly was created by the export. That is why, even if you call NinjaTrader indicators in the script, NinjaTrader asks and then adds them to the export if you try to export a script.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      571 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      331 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      549 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      550 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X