- ago
In one of my custom C# adapters, I have a configuration parameter added like below

CODE:
// Add other string and int parameters ... // Add enum parameter Parameters.Add(new Parameter("TOTP Hash Mode", typeof(TotpHashMode))          {             Hint = "Hash mode for your TOTP key. Default is SHA1. Check <a href="https://smartapi.angelbroking.com/enable-totp" target="_blank">https://smartapi.angelbroking.com/enable-totp</a> to get the TOTP key"          }); // Add other string and int parameters ...


In a method called "CreateParameters" of the same object, I am calling Parameters.Clone(). I am getting an exception on this "Clone" method call. Below are the exception details

Call Stack
CODE:
Unable to cast object of type 'System.Boolean' to type 'System.Int32'. at WealthLab.Core.Parameter.get_AsInt() at WealthLab.Core.Parameter.Persist(Tokenizer tok) at WealthLab.Core.ParameterList.Persist() at WealthLab.Core.ParameterList.Clone() at CW.WealthLab.WLConfigurationStore.CreateParameters() at CW.WealthLab.HistoricDataProvider.GenerateParameters()


If I comment out the enum-based parameter, the exception doesn't occur.
0
301
Solved
3 Replies

Reply

Bookmark

Sort
- ago
#1
Screenshot of the parameter just after adding it to the Parameters collection


0
Glitch8
 ( 10.62% )
- ago
#2
You haven't provided enough code to diagnose. Can you try to replicate the issue in a Strategy Initialize method? I have no trouble cloning a Parameter based on an enum:

CODE:
//create indicators and other objects here, this is executed prior to the main trading loop public override void Initialize(BarHistory bars) {          Parameter p = new Parameter("Test", typeof(ParameterType));          p = p.Clone();          WriteToDebugLog(p.Type.ToString()); }
0
Best Answer
- ago
#3
The issue was due to bad logic (I was creating duplicate parameter objects). Clone is working fine.

Thanks!
0

Reply

Bookmark

Sort