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

Custom Type Converter is displaying an error in the NT Log only after compiling

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

    Custom Type Converter is displaying an error in the NT Log only after compiling

    I have a property that uses a custom type converter to display a list of true/false options in an expandable list. The custom type converter is a subclass of ExpandableObjectConverter which is the standard way of creating an expandable list.

    Here is the problem:
    Every time a compile the indicator and then reload the the indicator I get an error in the Ninjatrader log that says " Failed to set property 'MyTestType' for indicator 'TestTypeConverter': Object of type 'MyNamespace.TestType' cannot be converted to type 'MyNamespace.TestType'.

    However, the property is being set properly.

    This error will only be displayed once. If I reload the indicator again I do not get the error message.

    I can even close the NinjaTrader application and then reopen it and the error message will not display again.

    So basically the indicator works fine. However, my concern is that if a person is using this indicator on their charts and then they decide to recompile any other indicator, then whenever they load my indicator for the first time or even refresh an existing indicator of mine then this error will appear in the log and the user may think something is wrong.

    Does anyone know why this error is only happening after a compile?

    Thanks
    P.S. I have included the source code below. You should be able to just copy it directly.
    Attached Files

    #2
    OK. so now I know that it is not something that I was doing wrong: I have the same problem, also because I am using a class to gather user input.

    Sorry that I cannot offer a solution. Indeed I am here to beg you to please publish the solution, if you are able to find one.

    Comment


      #3
      bmont,

      Thanks for your note.

      I was unable to replicate your issue the first time I loaded the indicator, but upon compiling a second time and reloading the indicator I did get this error message.

      Unfortunately coding on this level is unsupported, so hopefully someone in the community has a resolution. I will look into it further but I cannot promise a resolution quickly as first and foremost we must take care of supported issues.

      I suspect you are missing some code that would allow the compiler to interpret this appropriately.

      Please let me know if I may assist further.
      Last edited by NinjaTrader_AdamP; 11-23-2011, 01:57 PM.
      Adam P.NinjaTrader Customer Service

      Comment


        #4
        I have used TypeConverters in the past, was tricky, but it should work.

        Just from a glance at your code:

        Try putting the full class name including namespace:

        [TypeConverter(typeof(MyNamespace.TestTypeObjectCon verter))]
        public MyNamespace.TestType MyTestType
        {



        andreas

        Comment


          #5
          I've had similar issues, but under different circumstances. It seems the problem lies in the fact that your custom type persists between reloads of ninjascript, and is not disposed of with the rest of the indicator. The reason it happens only after a re-compile is that NT creates a new NinjaTrader.Custom.dll (it also generates a temporary version) and NT loses track of the undisposed type when ninjascript is reloaded again.

          My solution was to put a check in to see if there was a "recompile" done after the indicator had been added to a chart. If it has been recompiled, then your type will have to be disposed of separately, and you can't count on the normal disposal of the indicator.

          Like I said, my circumstances were different, but the effect was the same. I would get an error, only after a recompile of any indicator since my indicator was applied to a chart.

          Hope this helps.

          VT

          Comment


            #6
            Vtrader's comment makes sense.
            At this point you should put the typeconverter code in its own dll.

            Andreas

            Comment


              #7
              Thanks Andreas

              But things just got worse by moving them to their own DLL. I have seen this happen over and over again on the NinjaTrader platform. Whenever type converters and/or UITypeEditors are placed in a separate assembly they are no longer recognized by Ninjatrader. The indicators will still compile without warnings but they are not recognized by the settings property editor. This has been extremely frustrating. Many of the things I am trying to do should just work in a "normal" .NET environment. I will follow up with the steps that I took to put the TypeConverter in a separate assembly.

              Comment


                #8
                I have confirmed - as VTTrader mentioned in Post#5- that the user defined type is not disposed between recompiles of the NinjaTrader.Custom.dll.

                My question is.... how do I check to see if it has been recompiled. Do you have some example code on how to do this?

                Thanks

                Comment


                  #9
                  bmont,

                  The way I checked was using LastWriteTime, and basically compare timestamps.

                  fi = new FileInfo(NinjaTrader.Cbi.Core.UserDataDir.ToString() + @"bin\Custom\NinjaTrader.Custom.dll");
                  fileTime = fi.LastWriteTime;
                  VT

                  Comment


                    #10
                    I am hitting this same problem. Has anyone come up with a good answer for it? I even tried adding a conversion to the same type to the type converter, but that did not help.

                    I suppose it is not earth-shaking, but it is pretty darned annoying.

                    --EV
                    Last edited by ETFVoyageur; 03-18-2014, 06:32 PM.

                    Comment


                      #11
                      This is an old post. If anyone is still having the issue in NT8, I can post a solution.

                      Wil

                      Comment


                        #12
                        yes, please post your solution

                        Comment


                          #13
                          Originally posted by bltdavid View Post
                          yes, please post your solution
                          You need to implement it as ICloneable, and, of course, define a Clone() method. Often, just the default, base, shallow clone, Object.MemberwiseClone() method is sufficient.

                          Comment


                            #14
                            Implement it where?
                            On the TypeConveter classs?

                            Comment


                              #15
                              Originally posted by bltdavid View Post
                              Implement it where?
                              On the TypeConveter classs?
                              They have documented it rather quietly as an example.

                              ref: https://ninjatrader.com/support/foru...-grid-behavior

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by elirion, Today, 01:36 AM
                              2 responses
                              12 views
                              0 likes
                              Last Post elirion
                              by elirion
                               
                              Started by DJ888, 04-16-2024, 06:09 PM
                              5 responses
                              14 views
                              0 likes
                              Last Post NinjaTrader_Erick  
                              Started by samish18, Yesterday, 08:31 AM
                              4 responses
                              14 views
                              0 likes
                              Last Post elirion
                              by elirion
                               
                              Started by funk10101, Yesterday, 09:43 PM
                              1 response
                              14 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by TheWhiteDragon, 01-21-2019, 12:44 PM
                              5 responses
                              551 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Working...
                              X