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!

Wesley
  • 1,324
  • 1
  • 11
  • 27
  • Can you try clr.AddReferenceToFileAndPath? The . in the name shouldn't make a difference. – Jeff Hardy Jul 12 '11 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 '11 at 19:21
  • This problem seems to be cropping up elsewhere, too: [IronPython forum post](http://lists.ironpython.com/pipermail/users-ironpython.com/2010-May/012919.html), and [Another from the IronPython forums](http://ironpython.codeplex.com/workitem/26793?ProjectName=ironpython) – Wesley Jul 12 '11 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 '11 at 19:31

1 Answers1

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.

Community
  • 1
  • 1
Jeff Hardy
  • 7,632
  • 24
  • 24
  • 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 '11 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](http://www.elijahmanor.com/2009/09/recursively-unblock-assemblies-with.html) about a Microsoft Sysinternals utility called [`streams`](http://technet.microsoft.com/en-us/sysinternals/bb897440.aspx). The command `streams -d R.NET.dll` removed the block, and now `clr.AddReference("R.NET.dll"`) works. Huzzah! – Wesley Jul 12 '11 at 20:15