• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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.

    https://msdn.microsoft.com/en-us/library/w3f99sx1.aspx

    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,

    https://msdn.microsoft.com/en-us/lib...t.gettype.aspx

    Code:
    Type myType = new AddOns.AddOnTest().GetType();
    Code:
    Type myType = new Indicators.AddOnTestIndy().GetType();
    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:
      Type myType = Type.GetType("NinjaTrader.NinjaScript.Indicators.AddOnTestIndy");
      Type myType = Type.GetType("NinjaTrader.NinjaScript.AddOns.AddOnTest");
      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.

        http://stackoverflow.com/questions/1...m-returns-null

        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 Tiang, Today, 04:23 AM
          0 responses
          3 views
          0 likes
          Last Post Tiang
          by Tiang
           
          Started by gbux11, Today, 02:41 AM
          0 responses
          8 views
          0 likes
          Last Post gbux11
          by gbux11
           
          Started by TazoTodua, Today, 01:50 AM
          0 responses
          6 views
          0 likes
          Last Post TazoTodua  
          Started by lonestar, Today, 01:42 AM
          2 responses
          7 views
          0 likes
          Last Post lonestar  
          Started by CandySNK, Yesterday, 10:24 PM
          1 response
          21 views
          0 likes
          Last Post NinjaTrader_Marco  
          Working...
          X