Skip to content
April 20, 2010 / stevebaer

Rhino 5 and .NET Framework 4

This is not really a python post, but since this is my blog…

Visual Studio 10 was recently released and along with a new IDE comes a brand new version of the .NET runtime (.NET Framework 4). Like previous runtimes, this one is packed with new programming features to play with. Two of which that stand out to me are:

Questions have been coming in lately about Rhino 5’s support for .NET 4. Specifically; will we support it and how can we get plug-ins to work with it?

I downloaded the free express edition of C# 2010 and started tinkering with a plug-in that targeted .NET 4. The plug-in compiled without a problem, but as soon as I tried to load it into Rhino, bam!!! I got an error about attempting to load an assembly compiled for a different runtime. Sure enough, Rhino was continuing to load mscorlib for .NET 2.0. Something to note is that .NET 3.0 and 3.5 and really more like service releases to .NET 2.0 and the features of .NET 3.0/3.5 are available to Rhino plug-ins if those runtimes are installed on your computer. .NET 4 on the other hand appears to be a “major” release of the .NET runtime and for that reason was not getting loaded.

Without getting into technical .NET hosting details; I modified the Rhino core .NET plug-in loader to look for the .NET 4 framework on your computer and attempt to load it if it is installed. With this change, I was able to get my .NET 4 plug-in to load and run the following code

protected override Rhino.Commands.Result RunCommand(Rhino.RhinoDoc doc, Rhino.Commands.RunMode mode)
{
  // nothing like a little late binding
  dynamic d = doc.Objects;
  d.AddPoint(1, 2, 3);
  d = doc.Views;
  d.Redraw();
  return Rhino.Commands.Result.Success;
}

This change should show up in the next WIP of Rhino 5 (probably April 20th or 21st).

IMPORTANT
Existing Rhino plug-ins that target .NET 2 should still continue to work as they always have (maybe even better with .NET 4 performance enhancements.) That being said, we would really like to make sure that these plug-ins continue to work through testing instead of just making some blanket statement that your plug-ins will keep working as they always have. I would like to hear if anyone has problems running their existing plug-ins with this change in place. You will need to make sure that you have .NET framework 4 installed on your computer to test this
http://www.microsoft.com/downloads/details.aspx?FamilyID=9cfb2d51-5ff4-4491-b0e5-b386f32c0992&displaylang=en

If you do have problems, you can turn off the .NET 4 loading by running the test command TestDotNetRuntime and restarting Rhino. This test command toggles the .NET 4 loading feature on/off.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: