0

I need to call C# DLL (WPF application built using .NET) from ReactJS.

  1. I saw on one of the forums that we can use DLLExport in c# and use 'require' to import the DLL in NodeJS. I tried the same for my ReactJS app. But get error "require is not defined and have trouble resolving it for ReactJS. Please find the below link that I used as reference to make use of DLLExport and require.

https://www.youtube.com/watch?v=pN5NXDtOuek

  1. It was specified in the below forum that EdgeJS can be used as a bridge between NodeJS V8 and C# CLR. But haven't tried yet.

Call Function from DLL loaded in front-end javascript (load dll in clientside javascript)

Now, I wonder if I am using the right approach. Can NodeJS sample be used as reference to make ReactJS call DLL, as NodeJS is server side.

I would appreciate any pointers on this or kindly refer any material or documentation(for calling c# dll from reactJS). Thank you.

Sarahrb
  • 407
  • 11
  • 24
  • I have a feeling your solution is going to be NOT calling a dll from React. If you describe what you are trying to accomplish maybe there is a much more straightforward way. – Crowcoder Mar 18 '22 at 12:07
  • @Crowcoder No, I want to call the C# dll (created using WPF with .NET) from ReactJS. The label printer dll that is created by c#, basically generates and prints QR code on labels. We want to use those functionalities in ReactJS (by calling dll). Thank you. – Sarahrb Mar 18 '22 at 12:54
  • 1
    I don't think it is possible. Maybe if you took the code out of the WPF app and were able to compile it to webassembly.... I am confident you can generate qr codes and print them from javascript. Trying to re-use your WPF app in this way will be an exercise in frustration. – Crowcoder Mar 18 '22 at 13:16
  • Would you mind explaining me further. Is it because server side dll can't be run on client browser (ReactJS) ? whereas webassembly can be run on client browser if I am not wrong. – Sarahrb Mar 18 '22 at 13:58
  • 1
    Basically yes, it is because a browser cannot natively understand anything other than javascript or webassembly. Maybe [this would be of interest to you](https://stackoverflow.com/questions/67729887/how-can-i-make-wpf-app-to-work-on-a-web-browser) – Crowcoder Mar 18 '22 at 15:00
  • 1
    Blazor javascript interop is typically how you would achieve this. https://learn.microsoft.com/en-us/aspnet/core/blazor/javascript-interoperability/?WT.mc_id=dotnet-35129-website&view=aspnetcore-6.0 – GBourke Mar 18 '22 at 15:09
  • If JS running in a browser was able to call into a local DLL we'd all be in a world of hurt. This is why the browser sandbox exists. – Mike Lowery Aug 09 '23 at 22:41

0 Answers0