- ago
I try to use XmlSerializer in a C# coded strategy.

This requires a
CODE:
using System.Xml.Serialization;
statement and System.Private.Xml checked in Tools->Assembly References.

Strategy code compiles fine.:

CODE:
public class TradeInfo2 {    public string Symbol; } ... XmlSerializer serializer = new XmlSerializer(typeof(List<TradeInfo2>));


After "Start Backtest" I get:
"A non-collectible assembly may not reference a collectible assembly"

WHAT THE HELL IS THIS?

I've never seen such a message before.

The explanation here: https://learn.microsoft.com/en-us/dotnet/core/compatibility/core-libraries/7.0/collectible-assemblies
does not help anyway.

Any suggestions?
0
538
Solved
5 Replies

Reply

Bookmark

Sort
- ago
#1
It happens only, if the serialized class (here TradeInfo2) comes from the coded strategy.
0
Glitch8
 ( 12.10% )
- ago
#2
I was able to get this variation to run, don't know exactly why .NET is complaining about using the List directly.

CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Data; using WealthLab.Indicators; using System.Collections.Generic; using System.Xml.Serialization; using Steema.TeeChart; using System.Windows.Documents; namespace WealthScript1 {    public class MyStrategy : UserStrategyBase { //create indicators and other objects here, this is executed prior to the main trading loop public override void Initialize(BarHistory bars) {          XmlSerializer serializer = new XmlSerializer(typeof(TradeInfoList)); } //execute the strategy rules here, this is executed once for each bar in the backtest history public override void Execute(BarHistory bars, int idx) { if (!HasOpenPosition(bars, PositionType.Long)) { //code your buy conditions here } else { //code your sell conditions here } }       //declare private variables below }    public class TradeInfo2    {       public string Symbol { get; set; }    }        public class TradeInfoList    {       public List<TradeInfo2> TheList { get; set; } = new List<TradeInfo2>();    } }
0
Best Answer
- ago
#3
That worked, thanks!
0
- ago
#4
@DrKoch - In case you don't want to wrap the List<T> you could try the solution here involving DataContractSerializer: https://github.com/dotnet/runtime/issues/85142

I didn't try it. I don't know the implications, either.
1
- ago
#5
Thanks, Paul!
0

Reply

Bookmark

Sort