Skip to main content

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

The compileCsharp 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 type funid (function ID), used for subsequent calls to this function via the executeCsharp interface.

Basic Usage

Simple Example

Notes

⚠️ Important Limitations

  1. Managed DLL Limitation
    • The refs parameter can only reference managed DLLs (.NET assemblies)
    • For unmanaged DLLs, use DllImport
  2. 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)
  3. Namespace References
    • Must explicitly reference required namespaces (e.g., using System;)
    • Does not automatically reference all namespaces

Compilation Error Handling

If compilation fails, the interface will throw an exception.

Next Steps

After compilation, use the returned funid to call the function: See Execute C# Function to learn how to call compiled functions.

3.Execute Code

Execute C# Function

The executeCsharp 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

  1. 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
  2. funid Validity
    • funid is valid during application runtime
    • Needs to be recompiled after application restart
  3. Parameter Type Matching
    • Parameter types must match types in C#
    • Pay attention to numeric type precision issues
  4. Memory Management
    • Promptly release unmanaged resources in C#, release related resources after task processing
    • Fatal code defects may cause iClick to crash