New way to load a C# .net plugin


Hi guys, I put this post to share a new way to load a C# plugin.
Avoiding restart Rhino every time that recompile a plugin.
Using this technique the code compile and try time is more fast.

Managed Extensibility Framework (MEF) Plugin for Rhinoceros RhinoCommon

Hope will be usefull.

GrasshopperUnloadPlugin in rhino6
(Menno Deij - van Rijswijk) #2

I’ve tested this method today, and can report that it works. Thank you for making this technique available, this will certainly cut down our time spent in the compile-run-debug cycle. If only I knew about this four years ago :wink:


Even more faster:

If sometime must to change between many plugin, and write the full path dll name is a lack of time:
Store the default dll names in a txt file, doing this
not need to recompile the RhinoPluginLoader to change the default dll name,

In the LoadPlugin.cs, RunCommand change for this:

// Was a plugin named entered?
string plugin_name = gs.StringResult().Trim();
if (string.IsNullOrEmpty(plugin_name))
plugin_name = LoadDefaultDll();

Configuration txt file with the dll names:

D:\the path\plugin.dll
D:\the path\anotherplugin.dll
D:\the path\anothermoreplugin.dll

private string LoadDefaultDll() 
    string filename = @"D:\Visual Studio Projects\RhinoPluginLoader\defaultdll.txt";

    if (!System.IO.File.Exists(filename))
        Rhino.RhinoApp.WriteLine("defaultdll file not exist !!!");
        return "";
    StreamReader sr = new StreamReader(filename);
    string defaultdll="";
    if (!sr.EndOfStream)
        defaultdll = sr.ReadLine();//Load firt line
    return defaultdll;          

In rhino with two [ENTER] load the default dll.
Then you can run the first dll, or add more code to ask to user to enter a line number:

1 load first plugin
2 load second plugin


(Ibrahim Mahmoud) #4

This actually works! I didn’t know there were more options.

I use a program called SharpDevelop, a C# IDE, and it has the option of compiling the code without running it. I use that to save time, that’s also another option.


I am happy to also confirm this seems to be working…the restart/reload cycle was a deterrent for me to use c#.

I am fairly new to c# and was a little confused on the imports. I would recommend making the ‘RhinoPluginContract’ class first so you can reference it in the ‘RhinoPluginMakeLine’ and the ‘PluginLoader’, and you don’t get errors on the ‘IPlugin’ references. If you follow the flow in the article then you make the contract last.

I am using visual studio 2015 and the target for the new class library template was .net 4.5.2. I guess the Rhino template is set to 4.5.0, so I got a warning when compiling the ‘PluginLoader’. I just changed the target to 4.5.2 in project properties and it seems to be OK.

Thanks for sharing this!