Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Unable to Serialize Dictionary Running Live

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

    Unable to Serialize Dictionary Running Live

    Hello, I am trying to run a strategy using a dictionary that is of string and custom indicator. It works great in back tests, but I get this serialization error when trying to run it live.

    Error on executing DB command: System.InvalidOperationException: There was an error reflecting type 'NinjaTrader.NinjaScript.Strategies.T1V1S1V1FU'. ---> System.NotSupportedException: Cannot serialize member NinjaTrader.NinjaScript.Strategies.T1V1S1V1FU.Vari ablesDict of type System.Collections.Generic.Dictionary`2[[System.String mscorlib Version=4.0.0.0 Culture=neutral PublicKeyToken=b77a5c561934e089][NinjaTrader.NinjaScript.Indicators.ApolloAssetVari ables 0e14b8840c1d45c7a87f3e57b9425573 Version=8.0.26.0 Culture=neutral PublicKeyToken=null]] because it implements IDictionary. at System.Xml.Serialization.TypeScope.GetDefaultIndex er(Type type String memberInfo) at System.Xml.Serialization.TypeScope.ImportTypeDesc( Type type MemberInfo memberInfo Boolean directReference) at System.Xml.Serialization.TypeScope.GetTypeDesc(Typ e type MemberInfo source Boolean directReference Boolean throwOnError) at System.Xml.Serialization.StructModel.GetPropertyMo del(PropertyInfo propertyInfo) at System.Xml.Serialization.StructModel.GetFieldModel (MemberInfo memberInfo) at System.Xml.Serialization.XmlReflectionImporter.Ini tializeStructMembers(StructMapping mapping StructModel model Boolean openModel String typeName RecursionLimiter limiter) at System.Xml.Serialization.XmlReflectionImporter.Imp ortStructLikeMapping(StructModel model String ns Boolean openModel XmlAttributes a RecursionLimiter limiter) at System.Xml.Serialization.XmlReflectionImporter.Imp ortTypeMapping(TypeModel model String ns ImportContext context String dataType XmlAttributes a Boolean repeats Boolean openModel RecursionLimiter limiter) --- End of inner exception stack trace --- at System.Xml.Serialization.XmlReflectionImporter.Imp ortTypeMapping(TypeModel model String ns ImportContext context String dataType XmlAttributes a Boolean repeats Boolean openModel RecursionLimiter limiter) at System.Xml.Serialization.XmlReflectionImporter.Imp ortElement(TypeModel model XmlRootAttribute root String defaultNamespace RecursionLimiter limiter) at System.Xml.Serialization.XmlReflectionImporter.Imp ortTypeMapping(Type type XmlRootAttribute root String defaultNamespace) at System.Xml.Serialization.XmlSerializer..ctor(Type type String defaultNamespace) at NinjaTrader.NinjaScript.StrategyBase.ToXml() at NinjaTrader.NinjaScript.StrategyBase.DbAdd() at NinjaTrader.Cbi.DB.DBThread(),

    The custom indicator is basically just a new blank indicator with public properties I am using as variables. The reason I threw these properties in an indicator was because in NT can't serialize new files that aren't a strategy or an indicator(at leased that's the impression I've been given).

    Basically what I'm using this dictionary for is running multiple assets in the same strategy. Each item in the dictionary represents the variables for an asset. Using a dictionary like this is pretty crucial for the strategy, although if I am not able to use a dictionary I can probably get something else figured out.

    I have already tried repairing the DB as well.

    Any help would be appreciated!

    Thanks,

    -Parker

    #2
    Hello Parker,

    Unfortunately, Dictionaries cannot be public inputs. These will need to be private (access modifier).

    That said, for any types that can be properties, if these are public and not serializable, they will need to use the XmlIgnore attribute. (Dictionary would not count as one)
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you for the response! I switched the dictionary property from public to private, and it fixed the issue. Everything works great now!

      Thanks!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      46 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      22 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      33 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      50 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      42 views
      0 likes
      Last Post CarlTrading  
      Working...
      X