Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Share Service Error

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

    Share Service Error

    Hi There

    I developed a share service for publishing on Telegram.

    This share service runs fines when used in the code (in a strategy or an indicator) and NinjaTrader alerts.

    However, when I want to Share a Tab Content (via right click on the chart -> Share -> tab content) if fails stating: "Unhandled exception: Object reference not set to an instance of an object.

    I debugged the code using Visual studio 2019, and placed different breakpoints in the code to try to catch where the error is happening. Found nothing:

    The code goes to:

    - OnStateChanged() the state is State.SetDefault
    - Share service constructor
    - CopyTo(NinjaScript ninjaScript) ninjaScript is not null
    - OnStateChange() the state is State.SetDefault again
    - Share Service constructor
    - CopyTo(NinjaScript ninjaScript) ninjaScript is not null
    - Icon (get)


    Then the error arise.

    Do you have an idea of what could happen ?

    #2
    If you compile in Debug mode, then make the error happen, then go to Documents -> NinjaTrader 8 -> trace and look at the most recent trace file, do you then see the stack trace exhibiting the line number of your error?
    Bruce DeVault
    QuantKey Trading Vendor Services
    NinjaTrader Ecosystem Vendor - QuantKey

    Comment


      #3
      No line number, probably because the error come from outside the Share Service ?

      Here is the trace:

      2023-05-22 11:08:56:081 System.NullReferenceException: Object reference not set to an instance of an object.
      at NinjaTrader.Gui.Share.ShareServiceWrapper.set_Sign ature(String value)
      at NinjaTrader.Gui.Share.ShareServiceWrapper..ctor(Sh areService service)
      at NinjaTrader.Gui.Share.Share..ctor()
      at NinjaTrader.Gui.Share.Share..ctor(RenderTargetBitm ap screenCapture, String msg, ShareScreenshotType screenType)
      at NinjaTrader.Gui.Chart.ChartControl.<BuildMainConte xtMenu>b__381_12(Object _, RoutedEventArgs _)
      at System.Windows.EventRoute.InvokeHandlersImpl(Objec t source, RoutedEventArgs args, Boolean reRaised)
      at System.Windows.UIElement.RaiseEventImpl(Dependency Object sender, RoutedEventArgs args)
      at System.Windows.Controls.MenuItem.InvokeClickAfterR ender(Object arg)
      at System.Windows.Threading.ExceptionWrapper.Internal RealCall(Delegate callback, Object args, Int32 numArgs)
      at System.Windows.Threading.ExceptionWrapper.TryCatch When(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)​

      Comment


        #4
        Is there any NinjaTrader team member to help ?

        Comment


          #5
          Hello Philippe56140,

          Are you currently making the share service in a similar way to the existing Mail service that supports images? Have you tried debugging steps such as adding prints into your custom code or reducing the code you used to find where the error stops happening?

          Comment


            #6
            Answers are Yes and Yes. It seems the error come from outside the Share service but it may be linked to the share service in any way

            Comment


              #7
              Hello Philippe56140,

              I would suggest trying to duplicate the existing mail service code as a new service to see if you still get an error, if you don't then its a problem with a part of your code. If you do get the error without making any changes besides the required naming we could report that.

              Comment


                #8
                Thanks Jesse

                I duplicate the share service, leaving it with minimal code.
                Even though it is failing with the same error.

                Don't know what's wrong in this code;

                Code:
                    public class ShareService2: ShareService
                    {
                
                        private object icon;
                
                        /// <summary>
                        /// This MUST be overridden for any custom service properties to be copied over when instances of the service are created
                        /// </summary>
                        /// <param name="ninjaScript"></param>
                        public override void CopyTo(NinjaScript ninjaScript)
                        {
                            try
                            {
                                Print("37");
                                base.CopyTo(ninjaScript);
                                Print("39");
                
                                // Recompiling NinjaTrader.Custom after a Share service has been added will cause the Type to change.
                                //  Use reflection to set the appropriate properties, rather than casting ninjaScript to Mail.
                                PropertyInfo[] props = ninjaScript.GetType().GetProperties();
                                Print("44");
                                foreach (PropertyInfo pi in props)
                                {
                                    Print("47");
                                    if (pi.Name == "ID")
                                        pi.SetValue(ninjaScript, ID);
                                    Print("50");
                                    if (pi.Name == "Token")
                                        pi.SetValue(ninjaScript, Token);
                                }
                            }
                            catch (Exception e)
                            {
                                Print("Exception: " + e.Message);
                            }
                        }
                
                        protected override void OnStateChange()
                        {
                            if (State == State.SetDefaults)
                            {
                                Print("65");
                                IsConfigured                = true;
                                IsDefault                    = false;
                                IsImageAttachmentSupported    = true;
                                UseOAuth                    = false;
                
                                Description                                    = @"Send alerts.";
                                Name                                        = "ShareService2";
                
                                ID                                    = string.Empty;
                                Token                                = string.Empty;
                            }
                        }
                
                        public override async Task OnShare(string text, string imgFilePath)
                        {
                            Print("81");
                        }
                
                        public override async Task OnShare(string text, string imageFilePath, object[] args)
                        {
                            Print("86");
                        }        
                
                        public override async Task OnAuthorizeAccount()
                        {
                            Print("91");
                            return;
                        }
                
                        public override object Icon
                        {
                            get
                            {
                                Print("168");
                                if (icon == null)
                                    icon = System.Windows.Application.Current.TryFindResource("ShareIconEmail");
                                return icon;
                            }
                        }
                
                        #region Properties
                        [Display(ResourceType = typeof(Custom.Resource), Name = "ID", GroupName = "ShareServiceParameters", Order = 10)]
                        [Required]
                        public string ID
                        { get; set; }
                
                        [Display(ResourceType = typeof(Custom.Resource), Name = "Token", GroupName = "ShareServiceParameters", Order = 20)]
                        public string Token
                        { get; set; }
                        #endregion
                
                    }
                ​
                The execution tree is:

                65
                37
                39
                44
                ---- repeated
                47
                50​
                ----
                168

                Comment


                  #9
                  Please note that this Share service fails ONLY when used with Right click on the chart -> Share

                  Comment


                    #10
                    Hello Philippe56140,

                    It looks like you removed the default code and left only a shell. Do you see the error if you leave the default logic only making changes to the name and class so it appears as a new service? As it is not clear what may be causing that error we would want to know if you can reproduce that using known working code, the sample you just tested is not known working code that is just a base class which may be the reason its having an error. In your copy you can exclude the MailTypeConverter class because that is being pulled from the original file.

                    Comment


                      #11
                      Found the error:

                      Signature = "";

                      was missing

                      Comment

                      Latest Posts

                      Collapse

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