DLL could not be found exception while using RDotNet (R.Net) from C#

Jun 27, 2012 at 10:22 PM


I'm having trouble setting up and running the example from http://rdotnet.codeplex.com/. I keep on running into a DLLNotFoundException .

I downloaded the dll "R.NET 1.4"

Added it to my project as a reference.

Installed R and created a R_HOME environment variable.

Try to run the example and the exception occurs.

Following piece fails.

REngine.SetDllDirectory(@"C:\Program Files\R\R-2.15.1\bin\x64"


 using (REngine engine = REngine.CreateInstance("RDotNet", new[] {""}))   


The code is the same as the example at //http://rdotnet.codeplex.com/.

Thanks for all the help.

Jun 28, 2012 at 3:37 AM

You can look this post:http://rdotnet.codeplex.com/discussions/359534

I have the same problem.You can try resetup R,may be it will ok.

Use this code to load R.

public static string GetRPath()
            RegistryKey rCore = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\R-core");
            if (rCore == null)
                throw new ApplicationException("Registry key for R-core not found.");
            bool is64Bit = IntPtr.Size == 8;
            RegistryKey r = rCore.OpenSubKey(is64Bit ? "R64" : "R");
            if (r == null)
                throw new ApplicationException("Registry key is not found.");
            Version currentVersion = new Version((string)r.GetValue("Current Version"));
            string installPath = (string)r.GetValue("InstallPath");
            string bin = Path.Combine(installPath, "bin");
            // Up to 2.11.x, DLLs are installed in R_HOME\bin.
            // From 2.12.0, DLLs are installed in the one level deeper directory.
            return currentVersion < new Version(2, 12) ? bin : Path.Combine(bin, is64Bit ? "x64" : "i386");

And do like this code:

            REngine.CreateInstance("RDotNet", new[] { "-q" });
            REngine engine = REngine.GetInstanceFromID("RDotNet");

I hope it can help you.