Dear QC Community,
I am having a hard time setting up QC local and cloud development to be able to share code between multiple C# projects. There is documentation about how to share code between projects:
However, employing this method does not seem to work for me. It does not seem to work in local backtesting nor in the QC cloud. My goal is to have a way to use the same sharing technique in Visual Studio, local QC backtesting and in the QC cloud.
As an example, I create two projects “MyAlgo” and “MyCommonCode”. The goal is to share code from “MyCommonCode” in “MyAlgo”.
In order to achieve this I try the following: In my local directory, when I ran “lean init” I run:
# Create the two projects
lean create-project -l csharp MyAlgo
lean create-project -l csharp MyCommonProject
# Create solution as described in the documentation:
# https://www.quantconnect.com/docs/v2/lean-cli/tutorials/code-sharing
dotnet new sln
dotnet sln add MyAlgo
dotnet sln add MyCommonProject
With that, in Visual Studio, I have to add a reference to the project “MyCommonProject” in “MyAlgo”. Now I am able to use code, at least in Visual Studio, written in “MyCommonProject” in “MyAlgo”.
I then add some test class to “MyCommonCode” which I want to ruse in “MyAlgo”. Therefore, in “MyAlgo”, in “Main.ch” I have something like:
using MyCommonProject;
This works out fine in Visual Studio.
When running a local backtest, I get the following error:
lean backtest MyAlgo
[...]
CsMyCommonProjectShared -> /Compile/bin/MyCommonProject.dll
MyAlgo -> /Compile/bin/MyAlgo.dll
[...]
20220223 06:31:06.374 ERROR:: Engine.Run(): During the algorithm initialization, the following exception has occurred: Could not load file or assembly 'MyCommonProject, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'. The
system cannot find the file specified.
in BacktestingSetupHandler.cs:line 186 Could not load file or assembly 'MyCommonProject, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
When uploading the project to QC cloud I am not even able to build “MyAlgo” as it does not seem to know about the reference to "MyCommonProject".
16 | 01:38:48:
Build Error: File: Main.cs Line:2 Column:6 - The type or namespace name 'MyCommonProject' could not be found (are you missing a using directive or an assembly reference?)
What is the right (and elegant) way to achieve this?
Joseph Abrahamson
I am also running into this issue and would love to know if there's a resolution.
Louis Szeto
Hi Raffaele
We are able to reproduce this issue. Please follow this GH issue to subscribe to its progress of fixation.
Best
Louis
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Raffaele
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!