Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 rocketman7, Today, 02:12 AM
      5 responses
      23 views
      0 likes
      Last Post rocketman7  
      Started by trilliantrader, 04-18-2024, 08:16 AM
      7 responses
      28 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by samish18, 04-17-2024, 08:57 AM
      17 responses
      66 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by briansaul, Today, 05:31 AM
      1 response
      15 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by PaulMohn, Today, 03:49 AM
      1 response
      12 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Working...
      X