Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

107
Views
Call C# Method in JavaScript via WebAssembly

To give some context, I'm trying to connect an existing C# application with a React SPA. The problem is, that the C# code includes some really difficult mathematical calculations and I can't rewrite it.

My idea was to build a Blazor WebAssembly application, which includes the existing code base.

After countless hours of trying several different solutions, I figured out, that it's possible to copy the Blazor "_framework" folder (generated by building the project) into my React public folder. This allowed my to call static C# methods from my JavaScript code. All good so far, but unfortunately it's not possible to call non-static methods.

According to this article it should be possible to send the C# instance via IJSRuntime, but this isn't working for my case. From my perspective it looks like the IJSRuntime doesn't get injected because the JavaScript code is not part of Blazor.

Does anyone know any solution how to inject the IJSRuntime with the React environment? Or is there any better solution to call C# code from a React application?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Instead of going through all of this stuff, why not just use a simple REST API? You can simply implement an endpoint that accepts the parameters (via HTTP) and returns the result. In most cases, this is far easier to setup and maintain than other possible approaches.

Simply add:

app.UseEndpoints(endpoints => { endpoints.MapControllers(); });

Then just create your controller, which accepts your non-static services in the constructor (via dependency injection) that do the math, and return the values:

[ApiController]
class MathController : ControllerBase
{
  private readonly MyCalculatorService calculator;

  MathController(MyCalculatorService calculator) {
    this.calculator = calculator;
  }

  [HttpPost("api/math/my-math")]
  public async Task<ActionResult<MathResult>> MyMathEndpoint([FromBody] MathInput mathInput) {
    var result = calculator.GetResult(mathInput);

    return new JsonResult(result);
  }
}

MathInput and MathResult are just examples, but you can really use just about anything.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!