Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

System.Threading.Thread cannot be serialized because it does not have a parameterless

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

    System.Threading.Thread cannot be serialized because it does not have a parameterless

    Hello!

    When I start strategy I getting this error. Just in the process of strategy get this error.

    Default,Failed to execute DB job 'StrategyUpdateJob': There was an error reflecting type 'NinjaTrader.Strategy.Bot'.: Cannot serialize member 'NinjaTrader.Strategy.Bot.t1' of type 'System.Threading.Thread', see inner exception for more details.: System.Threading.Thread cannot be serialized because it does not have a parameterless constructor.,

    #2
    Evggne,

    Thank you for your post.

    Are you adding any thread properties through the strategy?

    If so you may need to add [XmlIgnore()] attribute before it so it does not go into serialization.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      That's part of the code. XML do not use.


      // This namespace holds all strategies and is required. Do not change it.
      namespace NinjaTrader.Strategy
      {
      /// <summary>
      /// Enter the description of your strategy here
      /// </summary>
      [Description("Enter the description of your strategy here")]

      public class Bot : Strategy
      {
      ......
      public Thread t1;
      ......
      protected override void Initialize()
      {
      CalculateOnBarClose = true;

      }

      private void LoginCallback(ISession session)
      {
      ....

      t1.Start();
      }

      private OnFailure FailureCallback(string failedFunction)
      {
      .....
      }

      private void SubscribePrice()
      {
      session.MarketDataChanged += MarketDataUpdate;
      session.Subscribe(.......);

      session.Start();
      ......
      }

      public void MarketDataUpdate(OrderBookEvent onOrderBookEvent)
      {
      .......

      DrawHorizontalLine(.....);
      DrawHorizontalLine(.....);


      swAllTextLine = ......

      File.AppendAllText(_filePathAll, swAllTextLine);

      if (.......)
      {
      if (....) { entryOrder = EnterLongStopLimit(.....); } else { entryOrder = EnterLong(.....); }
      }
      if (.....)
      {


      protected override void OnExecution(IExecution execution)
      {
      .............
      }

      public void NotifyStreamFailure(Exception exception)
      {
      ......
      }

      public void NotifySessionDisconnect()
      {
      ....
      }

      protected override void OnBarUpdate()
      {
      try
      {
      if (connect)
      {
      ......
      t1 = new Thread(SubscribePrice);
      t1.Name = t1.ManagedThreadId;
      t1.IsBackground = true;
      Api.Login(loginRequest, LoginCallback, FailureCallback("log in"));
      .....
      }
      if (dissconnect)
      {

      t1.Abort();

      }
      }
      catch (NullReferenceException e)
      {
      ......
      }

      Comment


        #4
        Evggne,

        Try using a private variable instead of a public -
        private Thread t1;

        Does this solve the error?
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          Yes, the problem is solved. Thank you very much!

          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