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:

  1. # Create the two projects
  2. lean create-project -l csharp MyAlgo
  3. lean create-project -l csharp MyCommonProject
  4. # Create solution as described in the documentation:
  5. # https://www.quantconnect.com/docs/v2/lean-cli/tutorials/code-sharing
  6. dotnet new sln
  7. dotnet sln add MyAlgo
  8. 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:

  1. using MyCommonProject;

This works out fine in Visual Studio.

When running a local backtest, I get the following error:

  1. lean backtest MyAlgo
  2. [...]
  3. CsMyCommonProjectShared -> /Compile/bin/MyCommonProject.dll
  4. MyAlgo -> /Compile/bin/MyAlgo.dll
  5. [...]
  6. 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
  7. system cannot find the file specified.
  8. 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".

  1. 16 | 01:38:48:
  2. 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?

 

 

Author

Raffaele

February 2022