5

I would like to use the R statistical package for some data crunching in an IronPython 2.7 application. I have found the R.NET assembly, which should make this possible. The problem is that IronPython refuses to load the R.NET assembly.

The code:

import clr  
clr.AddReference("R.NET")

Produces:

System.IO.IOException: could not add reference to assembly R.NET

The assembly is located in a file called R.NET.dll, which is stored in the same folder from which I am invoking ipy.exe. I have checked that the folder is on sys.path. I have tried variations like clr.AddReference("R.NET.dll") and clr.AddReferenceToFile("R.NET.dll"). None are successful.

Could the problem be that there is a dot (.) in the assembly name? How would I work around that?

FWIW I am using Windows 7, R 2.13.0, IronPython 2.7, v4.0 of the .NET framework, and R.NET 1.4. I can successfully add a reference to R.NET from the Visual C# Express IDE (under .NET 4.0), and reproduce the examples from the R.NET homepage.

Thanks in advance!

4
  • Can you try clr.AddReferenceToFileAndPath? The . in the name shouldn't make a difference.
    – Jeff Hardy
    Jul 12, 2011 at 18:01
  • clr.AddReferenceToFileAndPath returns: System.IO.IOException: file does not exist: C:\Users\wrbrooks\scratch\R.NET.dll. I assure you that the file does exist. I have tried specifying the path both with single slashes (`) and double slashes (\`).
    – Wesley
    Jul 12, 2011 at 19:21
  • This problem seems to be cropping up elsewhere, too: IronPython forum post, and Another from the IronPython forums
    – Wesley
    Jul 12, 2011 at 19:29
  • I tried clr.LoadAssemblyFromFile("R.NET.dll") and while it did not raise an exception, it also did not load the assembly (it returned a NoneType object, and import R.NET failed).
    – Wesley
    Jul 12, 2011 at 19:31

1 Answer 1

6

I'm going to guess that you use either Internet Explorer or Chrome, both of which mark downloaded files (with Zone.Identifier). .NET will refuse to load assemblies that are tainted with said mark.

To remove it, just unblock the R.NET.dll file. Now you should be good to go. I'll see if I can put in a better error message when trying to load such an assembly.

2
  • Weird. I do use Chrome, but there isn't an "Unblock" button in the R.NET.dll properties. It was downloaded as a .dll file, not in a .zip archive. Would that matter?
    – Wesley
    Jul 12, 2011 at 19:54
  • 2
    OMG, it worked. For future reference, there was no "Unblock" button in the properties of R.NET.dll, as shown in the blog post that @Jeff linked to. I worked around a (broken) link in that post, though, to this blog post about a Microsoft Sysinternals utility called streams. The command streams -d R.NET.dll removed the block, and now clr.AddReference("R.NET.dll") works. Huzzah!
    – Wesley
    Jul 12, 2011 at 20:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.