CodeStageGen

How to write a Code Stage in Blue Prism: inputs, outputs, namespaces and references

Updated 25 September 2026 · Every C# sample here compiles with the compiler that ships with Blue Prism.

A Code Stage is where a Blue Prism business object stops being drag-and-drop and runs .NET code you write. Used well, one Code Stage replaces a page of Loops, Decisions and Calculations. Used badly, it's a compile error nobody on the team can read.

This guide covers how Code Stages work: where the code goes, how inputs and outputs reach your code, which .NET type each Blue Prism data type becomes, and how to add namespaces and DLL references.

Where Code Stages live

Code Stages only exist in Object Studio. A process can't contain one; it calls an action on a business object, and that action's page holds the Code Stage. That's why reusable logic belongs in a VBO in the first place.

Two object-wide settings apply to every Code Stage in the object:

  • Language. C#, Visual Basic (.NET) or Python, set once for the whole object. You can't mix languages between actions.
  • Code Options. The DLL references, namespace imports and shared code the object is compiled with. You'll find them on the object's Initialise page: double-click the information stage at the top of that page to open the object's properties.

Step 1: set up Code Options

In the Code Options tab you'll see two lists:

  • External References: the .dll files the object is compiled against, such as System.dll, System.Data.dll and System.Xml.dll.
  • Namespace Imports: the using (C#) or Imports (VB) lines applied to every Code Stage, such as System, System.Data and System.Collections.Generic.

Anything your code uses has to be covered by both: the assembly in External References and the namespace in Namespace Imports. A missing namespace gives "The name 'Regex' does not exist in the current context". A missing reference gives "are you missing an assembly reference?" The compile errors guide lists the exact messages.

Shared helper methods go in Global Code. Blue Prism puts that block inside the class it compiles for the object, so fields, methods and even a constructor are allowed there, and every Code Stage in the object can call them.

Step 2: add the Code Stage and its parameters

Add a Code Stage to an action page and open it. It has three tabs:

  • Inputs: each input has a name and a Blue Prism data type. You map it to a data item or expression on the page.
  • Outputs: the same, for the values the stage returns.
  • Code: the body you write.

Blue Prism declares the inputs and outputs for you as variables. You don't declare them, and declaring one again is a compile error. The variable name is the parameter name with every character that isn't a letter or digit replaced by an underscore:

Parameter nameVariable in your code
Full NameFull_Name
Input CollectionInput_Collection
Amount (INR)Amount__INR_

Blue Prism data types in code

Blue Prism typeC# typeVB type
TextstringString
NumberdecimalDecimal
FlagboolBoolean
Date, DateTime, TimeDateTimeDateTime
TimeSpanTimeSpanTimeSpan
CollectionSystem.Data.DataTableSystem.Data.DataTable
Binarybyte[]Byte()

Two of these cause most of the trouble. Number is decimal, not double, so Total = 12.5; won't compile; write 12.5m. And a Collection is a DataTable: you read a cell with Items.Rows[i]["Column Name"], never Items[i].

Step 3: write the body

The Code tab takes a method body: no using lines, no class, no method signature. Read the inputs and assign the outputs. For example, a stage with input Full Name (Text) and outputs First Name and Last Name (Text):

C#
string name = (Full_Name ?? "").Trim();
int space = name.IndexOf(' ');
if (space < 0)
{
    First_Name = name;
    Last_Name = "";
}
else
{
    First_Name = name.Substring(0, space);
    Last_Name = name.Substring(space + 1).Trim();
}

Because the body is a method body, return; ends the stage early. That's handy for guard clauses.

Press Check Code before you close the stage. It compiles the object and lists any errors with their line numbers.

Step 4: fail loudly

When the input is wrong, throw an exception rather than returning a silent Success = False:

C#
if (string.IsNullOrWhiteSpace(Full_Name))
    throw new Exception("Full Name is empty - nothing to split.");

Blue Prism turns an exception thrown by a Code Stage into a Blue Prism exception, with your message in the detail. A Recover stage catches it like any other exception, and the message is what the controller sees in Control Room. That's much easier to support than a flag that someone forgot to check.

Things that catch people out

  • The compiler is C# 7.3. Blue Prism compiles with its own copy of Roslyn, not the one in Visual Studio. String interpolation ($"Hello {name}") works; C# 8 features such as ??= and switch expressions don't, and they fail with confusing syntax errors.
  • Pasting using lines into the Code tab. They belong in Namespace Imports. In the body they give CS1003: Syntax error, '(' expected.
  • Culture. Robots often run under a service account with different regional settings from your laptop. Parse dates and numbers with an explicit culture, as the dates guide explains.
  • Naming a Code Stage like its object. Blue Prism compiles the object into a class and each Code Stage into a method named after the stage. A stage named exactly like the object fails with CS0542, "member names cannot be the same as their enclosing type".

Where to go next

The Code Stages people write most are collection work: filtering without a loop, removing duplicates and parsing JSON. The performance guide explains when moving work off the canvas pays off.

More Code Stage guides