Using ROOT C++ libraries in a C# application under Visual Studio 2019

I need to process on-the-fly some data collected by a C# application (Windows Forms based on .NET framework under Visual Studio 2019) from an electronics board using ROOT classes like histograms, graphs, Minuit for fitting, etc. I guess I should either import the ROOT functionalities in the C# code, or have an independent ROOT-based C++ application running at the same time and talking with the C# application (?). After browsing some old posts in this forum I found that there is a package ROOT.NET which wraps the unmanaged ROOT C++ libs. But it looks like the package was not updated since a while. Could you, please, let me know what would be the most optimal up-to-date solution for my task?
Thanks a lot in advance.
Best, Gia

Hi Gia, @gwatts was the author (and maintainer) of ROOT.NET. I have no experience with interoperability between C# and C++, so I don’t know what would be the easiest solution for your use case. Maybe using a socket connection between your C# application and ROOT…

Hi @bellenot,
thank you for your reply. I found a solution which is so simple that it deserves to be shared here in case someone else also has a similar problem or just wants to create a nice GUI (C# Windows Forms) for a ROOT-based application. One needs to create a C++/CLR Class Library (.NET framework) project in Visual Studio. All necessary (for a given task) ROOT-based functionalities needs to be encapsulated in methods of the referenceable class(es) of the project. Afterwards, the library of this CLR project can be linked from the C# project (in my case: Windows Forms .NET framework) and that’s basically all one needs to do. C# accepts the C++/CLR classes which wrap the ROOT C++ classes. I have not checked too much of the ROOT functionalities in my tests yet but a histogram creation, filling, fitting and printing works fine.
Best regards,

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.