I am developping an application to analyse astronomical data in C# for Windows. For this, I use Visual Studio express 2013 and I would like to use Root class. So I download the last version of ROOTNET with nuGet. I have no problem during the installation and when I write my code in VS : I can access to ROOTNET class with automatic implementation and all library are in Reference of my project in VS
But, when I would like to compile, VS say me that root library (libMathCoreWrapper for exemple) are not find.

Do you have some idea ?

Thank you
Best Regards,

Hi Jean-Christophe,

I asked Gordon Watts (the author of ROOTNET) to take a look. You could also contact him directly

Cheers, Bertrand.

Hi Jean-Christophe,
you can use much simpler approach than one from Gordon Watts.
I created C# wrapper for some base ROOT (version 5.34) GUI classes.
Check attached files.

  • contains 2 files - ROOT.NET.dll, ROOTdotNET.dll which do the magic
    1. add them to the folder of your application and References

    2. create a simple WinForm

    3. add TCanvas user control to Visual Studio Toolbox
      General tab -> Choose Items -> Browse -> select ROOT.NET.dll

    4. put TCanvas control into form. Change its name in Properties to fCanvas

    5. is an example of application which executes hsimple.C macro and displays result in TCanvas control.

The code is very simple. Add event handler for “Run” button.

  private void OnClick(object sender, EventArgs e)
     var macro = "hsimple.C" + "(\"" + fCanvas.Name + "\")";

It executes hsimple.C(“fCanvas”) macro, where string “fCanvas” passed to the macro
is the name of TCanvas .NET control in which output will be displayed, so it could be any.

Here is result

Some simple mouse operations (zooming, moving object etc ) are available.

Regards. Valeriy

This example is for Visual Studio 2010 which is compatible with VS 2013 and higher.

ROOT.NET.dll, ROOTdotNET.dll compiled with .NET 3.5 but works well with .NET 4.0 and higher.

Personally I prefer to run ROOT macro embedded into resources
as well as ROOT.NET.dll, ROOTdotNET.dll files. (16.1 KB) (52.7 KB) (237 KB)

an example of zoomed histo

  • mouse double click resets zooming

Here are the classes docs. (237 KB)

I developed this package for my own purposes, but it has great potential for farther development,
i.e. integration ROOT with Visual Studio getting all goodies from there, like canvas/lines/histos etc.
attributes editing with Visual Studio Properties control … and much more. e.g. GUI building etc.

Since .NET has been ported by Mono to other platforms this approach could be perspective way
for ROOT GUI multi-platform development by replacing the current X95 GUI classes with
the-sate-of-the-art GUI .NET/WPF components.
Very interesting possibility is to elaborate existing Paint.NET (my favorite image editor) 3.5 code
which is under MIT licence to create commercial level canvas editor.

Regards. Valeriy

I think you are running into difficulty #2 (see below).

Ok - I tested a very simple program in VS 2013 Pro (I don’t have the express version handy) and it worked:

using ROOTNET;

namespace ALittleWork
    class Program
        static void Main(string[] args)
            var output = NTFile.Open("junk.root", "RECREATE");
            var h = new NTH1F("hi", "there", 10, 0.0, 10.0);

A few things, however. First, look carefully at your build output. Do you have any warnings? When I just built out of the box without paying much attention, I had two, one very important, and one less important.

  1. The less important one - the architecture mis-match. This is caused by the fact that ROOT is built only for x86 on Windows, and by default projects are AnyCPU in .NET. So to make sure it works properly in the end, it is best to build x86 .NET projects rather than AnyCPU (use the configuration manager to fix this).

  2. The second and more important thing, is a warning that says “ROOTSYS” isn’t properly defined, please exit and restart using the start_XXX.bat file. This means that ROOTSYS isn’t defined properly - either it is not defined at all on your system, or it is defined, but it doesn’t point to the proper version of ROOT. If you don’t fix this, you’ll get a “unable to load xxxWrapper.dll error”).

I hope this helps! Please let me know if you have any further trouble here!


Hmmm… so the difficulty here is that when the nuget package is installed it isn’t picking up the wrapper libraries. I suspect this is because you are using VS2013 rather than VS2015. I’m afraid I stopped supporting VS2013 a few years ago since 2015 came out and was a) free and b) better. :slight_smile: Is there any chance you can test this in VS2015?

I can test this to see what happens, but it involves spinning up a VM and installing VS2013, which has been



Thank you very much for your help.
I try to use class of Valeriy and it works. It’s one solution but I will prefer to use ROOT.NET.

So, I modify the start_XXX.bat because the path were wrong. I lunched again but, I have no difference.
If I must to update my VS 2013 to 2015, I will do that and try again.

Best Regards,

The path is wrong - can you show me what the path is there and what is the correct path?

It is very important that the .NET version of ROOT and the binary C++ version of ROOT match. That start_xxx.bat file is specifically designed to do that.

Did you change it because you wanted to use your version of root that you’d downloaded and installed? By default, the nuget package will download the proper version of root and place it in your tmp directory. Try started VS2013 with the start_XXX.bat and see if it works.

I tested with VS2013 when I wrote the above email message and it worked just fine.


No, I don’t change path to my root’s folder. The orignal path was :
And I change to :

Maybe the ~ is not a problem in this case, but sometimes I notice that it can cause some error.

I download .NET version of ROOT from nuget (5.34.36) and I download and I install from root website the same version (5.34.36). I just don’t understand how ROOT.NET make the link with the C++ root which is installed in my computer.

Thank you for your help.
Best Regards,

Hmmm… Ok. That is very interesting… the long path name like that is something I’ve never tested. I wonder if that is getting in the way somewhere else?

If you have the same version installed on your computer, and ROOTSYS points to it, and visual studio knows about that environment variable, it will attempt to use that version of root as long as the version numbers match.

If they don’t match, then it will download the proper version of root during the build (when you first built the code after installing the nugget package you may have noticed a long lag time - that was the download and unpacking going on). You can look at that path that is in the bat file to assure that it is present.

Since the build process couldn’t find your version of ROOT you installed, you should double click on that .bat file to start the environment.

Now, if you do a build (or a rebuild), you should look to make sure you have no errors and or warnings.

If you then click “run”, then it should work. I’m assuming that you’ve done all of this, but when you click “run” it still fails with these errors about not loading one of the wrapper DLL’s. Is that correct?

BTW, if you are trying to run outside of the IDE, then you need to make sure the process/command shell/whatever has run those first two lines of the .bat file to point to the “correct” version of the ROOT binaries.

Hi, Do you have the dll files that also include basic histogram functionalities as well?