Quick Answer
The build error "Assembly must contain algo type" (CT0002) means that cTrader Automate expected to find a cBot, indicator or plugin class in your project, and found none. According to the cTrader documentation on compiling, the message appears when a class library project references the cTrader.Automate NuGet package but contains no cTrader algo classes. The package turns on a build step that makes an .algo file, and that step needs at least one algo.
There are three common fixes. If the project is a shared library (helpers, indicators' math, models), set <AlgoBuild>false</AlgoBuild> in its .csproj, which is the fix the documentation gives. If the project should be a cBot or indicator, make sure it has a public class that inherits from Robot or Indicator and has the matching attribute. If the class exists but is not found, check that it is public: a forum thread on the same error was solved by changing an internal class to public. This post shows each case, a minimal valid cBot, and how to split a solution into a library and a cBot.
From the author: I build cBots in cTrader Automate and in Visual Studio Code, and I convert strategies from Pine Script and MQL5 to C#. The error shows up the day a developer moves shared code into its own project. In MQL5 you would use an include file for that, and the cTrader side has no direct copy of the idea.
Key Facts
| Situation | Why CT0002 appears | Fix |
|---|---|---|
| A class library that references cTrader.Automate | The package builds an .algo file and the library has no algo | <AlgoBuild>false</AlgoBuild> in the library .csproj |
| A cBot project without a Robot class | No algo type in the assembly | Add a public class that inherits Robot with the [Robot] attribute |
| An indicator project without an Indicator class | Same | Add a public class that inherits Indicator with the [Indicator] attribute |
| The class exists but is internal | A forum thread was solved by making it public | Declare it public |
| The project was moved to .NET 6 or newer | Libraries that referenced cAlgo.API.dll now reference the package | Use AlgoBuild false for the libraries |
What the Error Looks Like
In forum threads, the message is posted in forms such as Assembly must contain algo type. [C:\...\MyProject.csproj] (CT0002) and Error CT0002 Assembly must contain algo type. The path points to the project that failed. The first thing to read is therefore which project is named: the cBot, or a library next to it.
Cause 1: A Class Library With the cTrader.Automate Package
You move your helper code (a risk calculator, a signal class) into a separate project, add the cTrader.Automate package so that the code can use cAlgo.API types, and the build fails. The package is meant for projects that produce algos, so its build step runs by default. The documentation shows this project file for a library (the target framework is the one in its example; use the one your solution uses):
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AlgoBuild>false</AlgoBuild>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="cTrader.Automate" Version="1.*-*" />
</ItemGroup>
</Project>
The documentation describes AlgoBuild as the switch that enables building .algo files, and says that its default is True. With false, the library builds as a normal library. Two forum posters confirmed that adding this property fixed the error in their library projects.
Cause 2: A cBot or Indicator Project With No Algo Class
A project that is supposed to be a cBot needs a class like this one. This is a complete cBot that only prints, so you can test the build without any trading code:
using cAlgo.API;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class MinimalBot : Robot
{
protected override void OnStart()
{
Print("MinimalBot started on {0}", SymbolName);
Stop();
}
}
}
The class is public, inherits from Robot, and has the [Robot] attribute. An answer from the cTrader team in a forum thread says the error appears when a project references the cTrader Automate API but does not include an algo class. For an indicator, use [Indicator(...)] and inherit from Indicator.
Cause 3: The Class Is Not Public
One poster built an indicator with the 4.3 API and got CT0002: Assembly must contain algo type, while the same project had worked with 4.1. The problem was solved after the poster changed a class declared internal to public. If your algo class has no access modifier at all, C# makes it internal, so write public on purpose:
// not found: no modifier means internal
class MyIndicator : Indicator { /* ... */ }
// found
public class MyIndicator : Indicator { /* ... */ }
Two Projects: A Library and a cBot
A common layout is one cBot project and one library project, in the same solution. The library has AlgoBuild set to false (Cause 1). The cBot project has the Robot class and refers to the library with a project reference. Check this layout by building the whole solution on your machine: I have not built it for this post, and the exact way that cTrader finds the library at run time depends on the version, so read the compiling page of the documentation before you depend on it.
If you are not ready for two projects, the simplest layout is one project with the helper classes in a separate file (a plain .cs file next to the cBot). That builds as one algo and avoids the question.
A Different Message With a Similar Name
A thread from 2024 posted the message "assembly code must contain single algo type". The only reply pointed to the documentation on compiling, and the thread does not state a cause. Do not assume that it has the same fix as CT0002. If you see that wording, read the compiling page of the cTrader documentation and check how many algo classes your project has.
Common Habits That Lead Here
| Habit | What goes wrong | Do this |
|---|---|---|
| Moving helpers to a library and adding the Automate package | The package expects an algo | AlgoBuild false in the library |
| Copying a class from a forum with no modifier | The class is internal | Add public |
| Deleting the Robot class while refactoring | The project has no algo | Restore it or turn the project into a library |
| Upgrading from .NET Framework to .NET 6 | Libraries referenced cAlgo.API.dll before | Reference the package and set AlgoBuild false |
| Two algo classes in one file by accident | Not confirmed as a cause of CT0002 | Keep one algo class per file and read the build output |
Other Build Errors You May Meet Next
| Message | What it means | Where to look | |---|---|---| | CS0246 | A type or namespace is not found | CS0246 | | CS0534 | An abstract member is not implemented | CS0534 | | CS1002 / CS1513 | A semicolon or brace is missing | CS1002 and CS1513 | | CS0103 | A name does not exist in this context | CS0103 | | CS0117 | A type does not contain a definition | CS0117 |
Checklist: What to Check When You See CT0002
- Read the project path in the message: which project failed?
- Is it a library? Add
<AlgoBuild>false</AlgoBuild>to its.csproj. - Is it a cBot or indicator? Check that it has a
publicclass that inheritsRobotorIndicator. - Check the attribute (
[Robot]or[Indicator]) on that class. - Write
publicon the class instead of relying on the default. - Build the whole solution and read the first error, not the last.
- Run the minimal cBot above to confirm that the toolchain works.
- Test on a demo account before the cBot trades with real money.
Common Mistakes
- Adding the Automate package to every project of the solution.
- Leaving a class without an access modifier.
- Fixing the wrong project: the error names one project.
- Treating "single algo type" as the same error without reading the docs.
- Deleting the algo class while moving code into a library.
- Skipping the build of the whole solution after a change.
FAQ
Related Guides
- Pine Script to cTrader C# cBot: the full conversion process, including the cBot class.
- cTrader C# error CS0246: a type or namespace that is not found.
- cTrader C# error CS0534: a missing member of an
IndicatororRobot. - cTrader C# errors CS1002 and CS1513: a missing semicolon or brace.
- cTrader C# error CS0103: a name that does not exist in the context.
- cTrader volume is in units, not lots: a common first-cBot mistake after it builds.
- cTrader order failed: TradeResult error codes: read the result of an order.
- What to check in a trading bot before going live: a pre-live checklist.
- cTrader cBot crashed: Error # with a long number: find the exception behind a crash.
Fix Compile Errors Without Guessing
If a cBot does not build, paste the code and the error message into the CodeFlowOS Error Fixer. It suggests a minimal fix, explains each error and shows what changed. A fix uses 1 credit, with up to 3 attempts included, and the compiler check is optional. Outputs are not guaranteed, and code that compiles can still have wrong trading logic, so always review the result. Before a bot goes live, the Code Review is free during the early-bird period. CodeFlowOS also converts strategies between Pine Script, MQL5 and cTrader C#: try the converter page.
This article is educational. It does not describe trading performance and is not financial advice. Always build the code in cTrader Automate and test it on a demo account before using it on a live account.