In my current desktop application, I evaluate dynamic C# formulas at runtime using CodeDomProvider. The formulas are written as C# snippets, and from each snippet I generate a full class and method, compile it in-memory, and invoke it with parameters.
For example, I may have a formula stored as a string like this:
var test10 = "";
if (mdDate0 != DateTime.MinValue)
test10 = test10 + mdDate0.ToString("dd.MM.yyyy");
if (mdTextBox9 != "" && test10 != "")
test10 = mdTextBox9 + ", (" + test10 + ")";
else
test10 = string.Empty;
return test10;
Before executing this, I parse the formula and extract variable names (based on @VariableName), then automatically generate a C# class like this:
using System;
namespace ExpressionEngine {
public class InMemoryEngine {
public object EvaluateCode(DateTime mdDate0, string mdTextBox9) {
var test10 = "";
if (mdDate0 != DateTime.MinValue)
test10 = test10 + mdDate0.ToString("dd.MM.yyyy");
if (!string.IsNullOrEmpty(mdTextBox9) && !string.IsNullOrEmpty(test10))
test10 = mdTextBox9 + ", (" + test10 + ")";
else
test10 = string.Empty;
return test10;
}
}
}
I dynamically compile and execute this using CodeDom in C#, and pass in the parameter values at runtime.
Now I’m building a React web application and want to support the same dynamic formula logic, but fully in the browser, without sending formulas to a backend server for evaluation.
Key requirements:
The formulas are already written in C# and I have many of them (over 5000).
They should be evaluated dynamically on input change events (e.g., onChange of an input field).
I want to avoid rewriting all the formulas manually in JavaScript or TypeScript.
The execution must happen entirely in the browser (no API/server call).
Question: Is it possible to execute raw or compiled C# code dynamically in the browser, from a React app?
Are there tools like Blazor WebAssembly, Mono WASM, or something else that can help me evaluate C# methods dynamically with parameter input?
Can I somehow reuse my current formula engine (or its structure) in the browser via WebAssembly, even if it requires some adaptation?
Any guidance or examples would be greatly appreciated. I’m looking for the most practical way to execute C# logic client-side in React with minimal rewriting of existing code.
I tried researching how to run C# in the browser and came across Blazor WebAssembly and Mono WASM, but from what I understood, they are designed for building entire applications, not for dynamically compiling and running custom C# code snippets with parameters (like my formulas).
I also looked into Roslyn and CodeDOM, but those seem to work only in .NET server environments, not in the browser.
I was expecting to find a way to load and execute simple C# methods (compiled or interpreted) entirely in the browser, passing values to parameters just like I do with CodeDomProvider in my desktop app. Ideally, I hoped for some WASM-based interpreter or runtime that would allow this without rewriting everything in JavaScript.
So far, I haven't found a clear way to do this in the browser from a React app.
Expressiontree. When running in an environment without a compiler, the expression tree will be interpreted instead.($a * 2 > 10) || $b.