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

Problem after Compiling to Assembly

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

    Problem after Compiling to Assembly

    Here are 2 very simple scripts.. One being an addon and the other being an indicator.. Both somewhat using each other..

    Both TestMethods in each work perfectly when the scripts are in cs form (although still not sure why the active state of the addon prints before the config state), but once I compile either one of them (or both) into an assembly and use that/them instead,

    Both stop working.. Well they still work/run, but once compiled, the types always come back null..

    Please Advise..

    Thanks


    Attached Files
    -=Edge=-
    NinjaTrader Ecosystem Vendor - High Tech Trading Analysis

    #2
    Hello -=Edge=-, and thank you for your question.

    Type.GetType is an MSDN C# method, and so we can only provide limited support. I would like to invite you to review their publicly available documentation.



    That said, it is very easy to get a C# type when you have an object reference handy. The following two lines of code will return the same Type objects you are seeking. They rely on Object.GetType, documented publicly here,



    Code:
    [FONT=Courier New]Type myType = new AddOns.AddOnTest().GetType();[/FONT]
    Code:
    [FONT=Courier New]Type myType = new Indicators.AddOnTestIndy().GetType();[/FONT]
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      Thanks Jessica

      Although that might work (well it does in cs form anyway), I was really wanting to pass in a string there to the GetType()...

      Not to mention if you add those hard coded references to your script like that, when you go to export the assembly with NT, NT won't let you export unless you include those referring scripts as well.. So now you go to export the Indy, and it wants to add the addon and any other (indys in this case) that addon might reference to the compiled assembly.. This would not be good nor desired...

      Is there a reason why these work just fine when scripts are in default cs form, but as soon as you compile either or both they no longer pass those types correctly?

      Code:
      [COLOR=#006400]Type myType = Type.GetType("NinjaTrader.NinjaScript.Indicators.AddOnTestIndy");[/COLOR]
      [COLOR=#006400][COLOR=#006400]Type myType = Type.GetType("NinjaTrader.NinjaScript.AddOns.AddOnTest");[/COLOR][/COLOR]
      Last edited by -=Edge=-; 12-09-2016, 02:14 PM.
      -=Edge=-
      NinjaTrader Ecosystem Vendor - High Tech Trading Analysis

      Comment


        #4
        We can only provide limited support regarding undocumented functionality. That said, I have found a relevant publicly available Stack Overflow discussion on this topic.

        I have a snippet of code in my application (which references System.Windows.Forms) which attempts to resolve type information for a Form class like so: Type tForm = Type.GetType("System.Windows.Fo...


        It states that in order to accomplish this using a string, you will need to use the assembly qualified name of the type. An example is provided behind that link that will enable you to learn the assembly qualified name of the type you are referencing, and another example is provided where this name is used.

        Please let us know if there are any other ways we can help.
        Jessica P.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_JessicaP View Post
          It states that in order to accomplish this using a string, you will need to use the assembly qualified name of the type.
          Thanks.. problem is that really wasn't a good option for me in this particular case either.. but with some research, a lot of playing, and too much time, I believe I've figured out yet another work around to accomplish what I was looking for.. Turns out NT actually provides a list for the addons.. So this ended up working for that..

          Code:
          dynamic myType = NinjaTrader.NinjaScript.AddOnBase.AddOns.FirstOrDefault(x => x.Name.ToString().Equals("myString")).GetType();
          I couldn't find an equivilant for the Indicators, but stumbled accross a thread that lead me to try this.. which seems to work..

          Code:
          dynamic myType = NinjaTrader.Core.Globals.AssemblyRegistry.GetDerivedTypes(typeof(IndicatorBase)).Where(x => x.Name.ToString().Equals("myString"));
          I could have probably used this for the AddOnBase as well, didn't try, as already had the previous code working..


          -=Edge=-
          NinjaTrader Ecosystem Vendor - High Tech Trading Analysis

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by cre8able, Today, 03:20 PM
          1 response
          9 views
          0 likes
          Last Post cre8able  
          Started by fiddich, Today, 05:25 PM
          0 responses
          3 views
          0 likes
          Last Post fiddich
          by fiddich
           
          Started by gemify, 11-11-2022, 11:52 AM
          6 responses
          804 views
          2 likes
          Last Post ultls
          by ultls
           
          Started by ScottWalsh, Today, 04:52 PM
          0 responses
          4 views
          0 likes
          Last Post ScottWalsh  
          Started by ScottWalsh, Today, 04:29 PM
          0 responses
          7 views
          0 likes
          Last Post ScottWalsh  
          Working...
          X