---
version: "2026.1.0"
language: "en"
---
# C# Code

The **C# Code** block lets you run custom C# logic that is not directly available through standard LEAPWORK building blocks, for example parsing a JSON object or reading values from XML. This block is useful when a scenario is easier to solve through code than by combining standard blocks.

Fully expanded, the **C# Code** block shows the following properties:  
![image-20260428-070509.png](https://docs.leapwork.com/__attachments/a_7ce35192f956b8f7a2141438143233f3d744255843a5cea60612d6fa62c265a5/image-20260428-070509.png?cb=05bf600eb6671762dfd675eb08cd4bc2)

**Note:** The screenshot on this page uses the **2026.1**version. If you are using an earlier version, your layout may look different.

## Quick-start

1. Drag **C# Code** onto the canvas.

2. Connect the block in the flow and optionally specify the basic parameters required for this block to operate, listed by their exact UI labels in one line: **Click to edit** , **Text fields** , **Default timeout** , **Timeout (sec)**. For details on how to work with the editor modal, see

3. Run the flow when it's ready.

## Building block parameters

Parameter  
* **Block header:** Shows the current name of the **C# Code** block. You can rename it by double-clicking the header and typing a new title.

* **Click to edit:** Opens a popup editor for C# code. A sample code snippet is available to show the entry point for code to be written. Write your code in the editor and select **Run** to compile and execute it. If you want to debug the code, you can call `LogMessage()` multiple times and then run the code to inspect intermediate results.

* **Text fields:** Stores key value pairs that can contain dynamic content and be used as tokens. These fields are maintained as `Dictionary<string, object>`. You can collect and type cast values in your C# code as required. The fields you add here are also shown in the editor under the **Fields** tab.

* **Error occurred:** Triggers if a runtime error occurs while executing the C# code during case execution.

* **Default timeout:** Controls how the block timeout is determined. If **Default Timeout** is unchecked, the timeout value is **60 seconds** . If **Default Timeout** is checked, the flow setting for **Default timeout** is applied.

* **Timeout (sec):** Sets the maximum time allowed for executing the code, including processing input and producing output. If execution is unsuccessful within the specified time, the block triggers **Error occurred** .

  **Note:** All cases have a global timeout that can be configured in the **Settings** panel. This is unrelated to the timeout of a single building block. A running case is automatically cancelled if it runs longer than the global timeout.

## Using the editor tabs

### Source code

Use this tab to write the C# logic. Select **Run** to compile and execute the code. If you need to debug, you can add multiple `LogMessage()` calls and run the code to inspect intermediate values.  
![image-20260428-070339.png](https://docs.leapwork.com/__attachments/a_50f6b57009e149f63da4f02650dcf7f6768940250f133b689792990d10741fd0/image-20260428-070339.png?cb=95a85d3828b2115b32ce2753baa35844)

### Fields

Fields are used to provide input and output data from code. You create them in the block's **Text fields** parameter and they appear in this tab for review and editing. In code, they are available through a dictionary structure and can be collected and type cast as needed.  
![image-20251222-130942.png](https://docs.leapwork.com/__attachments/a_086ce5a7e8291e1c6ed2ea37307a1bc0e781ab767d2029bf766980d432d50af0/image-20251222-130942.png?cb=295bd82d74d54614c5bd51f864764db7)

### References

Before writing code against an external component or connected service, the block must include a reference to it. Use this tab to add external references or dependencies. For example, parsing JSON may require adding `Newtonsoft.Json.dll`.  
![image-20251222-131023.png](https://docs.leapwork.com/__attachments/a_9049689aac1d27819e0ae55fe95a7452a895cbbca7ddcbcfaf4656adafdefd1d/image-20251222-131023.png?cb=d7e18a704db6449e34f43470eaa093b6)

You can add references in the following ways:

* **From file** -- Browse and add a specific DLL file manually.

* **GAC** *(up to 2025.2 only)* -- Add files from the Global Assembly Cache when available. GAC is not supported in .NET 8 and is no longer available starting **2026.1**.

* **System Assemblies** *(2026.1+)* -- Select from a list of .NET 8--compatible system libraries bundled with the LEAPWORK installation. This option replaces GAC.

#### System Assemblies *(2026.1+)*

With the migration to **.NET 8** , Global Assembly Cache (GAC) is no longer supported. The **System Assemblies** option under the References tab lets you add common system libraries directly, without manually locating DLL files.

1. Open the **C# Code** block editor and go to the **References** tab.

2. Click **System Assemblies** and use the filter to find the required DLL.

3. Select one or more libraries and click **OK** , then **Save**.

To remove a system assembly, deselect it in the **System Assemblies** dialog (or delete the reference from the list) and click **Save**.  
![image-20260428-065748.png](https://docs.leapwork.com/__attachments/a_6daf1052aa6065810b0612e1c247559f40202c8bda220aa19cf5c8fc24a46db5/image-20260428-065748.png?cb=274d55f41f762725a394d6bb0ab8af8a)

## Examples

Use **JSON_XML_Parser.zip** as a reference package. The zip contains two sample flows that demonstrate how to parse JSON and XML using the **C# Code** block.

Import the package and reuse or adapt the flows for your own scenarios.

[JSON_XML_Parser.zip](https://docs.leapwork.com/__attachments/a_e07f5860e7e6d63c99c3ae3caa25e2dfc037716fbb7e1a61d062dc0157d6d9d0/JSON_XML_Parser.zip.md?cb=787b3297a0e2b414d163ccdcb1889fe2)  
**Note:** This package can be imported into the same LEAPWORK version it was created in, or any newer version. Importing into older versions may fail due to compatibility differences between releases.

## Resources

|                                                **Topic**                                                |                                                  **Description**                                                  |
|---------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------|
| [Flows FAQ](https://docs.leapwork.com/faq/latest/leapwork-flow-faq/flows-faq.md)                                                 | Common questions about creating, running, and managing flows in Leapwork.                                         |
| [Flows Troubleshooting](https://docs.leapwork.com/troubleshooting/latest/leapwork-flow-troubleshooting/flows-troubleshooting.md) | Guidelines and solutions for identifying and fixing issues that occur when building or running flows in Leapwork. |