1.Overview
💡 Unlimited PossibilitiesIf you’re familiar with C#, you can use this interface to build any low-level functionality and high-performance algorithms. Whether it’s system-level operations or calling third-party DLL libraries!
Use Cases
Scenarios Suitable for C# Runtime:
- 🧮 Algorithm Computation - Execute compute-intensive algorithms (such as image processing, data analysis)
- 📦 Third-party Library Integration - Call existing .NET libraries (such as OpenCV、YOLO operations, etc.)
Ready to Use
🔧 Powerful Ecosystem
- Access .NET Class Libraries - Can use the entire .NET Framework/Core class library
- NuGet Package Support - Can reference and use third-party libraries from NuGet
⚡ High-Performance Hybrid Programming
- Best Practice Combination - Can leverage C# to handle compute-intensive tasks
- In-Process Calling - C# code is compiled before running, with extremely low call overhead
- Async Support - Full support for async/await, fully utilizing asynchronous performance advantages
2.Register Code
Compile and Register C# Code
ThecompileCsharp interface is used to compile C# source code and return a unique function ID (funid) for subsequent calls.
Endpoint Description
Endpoint Type
Parameters
Response Payload
Returns a string typefunid (function ID), used for subsequent calls to this function via the executeCsharp interface.
Basic Usage
Simple Example
Notes
⚠️ Important Limitations
- Managed DLL Limitation
- The
refsparameter can only reference managed DLLs (.NET assemblies) - For unmanaged DLLs, use
DllImport
- The
- Fixed Class and Method Names
- Class name must be
Startup - Method name must be
Invoke - Signature must be
public async Task<object> Invoke(dynamic args)
- Class name must be
- Namespace References
- Must explicitly reference required namespaces (e.g.,
using System;) - Does not automatically reference all namespaces
- Must explicitly reference required namespaces (e.g.,
Compilation Error Handling
If compilation fails, the interface will throw an exception.Next Steps
After compilation, use the returnedfunid to call the function:
See Execute C# Function to learn how to call compiled functions.
3.Execute Code
Execute C# Function
TheexecuteCsharp interface is used to execute C# functions that have been compiled and registered through compileCsharp.
⏱️ Cold Start Time
First execution will have 50-200 milliseconds of cold start time, subsequent calls have no overhead.
Endpoint Description
Endpoint Type
Parameters
Response Payload
Returns the execution result of the C# function, type depends on the C# function’s return value.Basic Usage
Complete Flow Example
Magic Parameter Variables
iClick provides special magic variables that can dynamically obtain system data during calls. Magic variables start with$. and are automatically parsed to actual data before execution.
Available Magic Variables
Notes
⚠️ Important Notes
- Magic Variable Usage Rules
- Magic variables must be passed as strings (e.g.,
"$.screenshot('id')") - Magic variables are automatically parsed to actual data before execution
- Magic variables must be passed as strings (e.g.,
- funid Validity
- funid is valid during application runtime
- Needs to be recompiled after application restart
- Parameter Type Matching
- Parameter types must match types in C#
- Pay attention to numeric type precision issues
- Memory Management
- Promptly release unmanaged resources in C#, release related resources after task processing
- Fatal code defects may cause iClick to crash

