How to ensure my Rhino Plugin loads the correct DLL?


#1

My Rhino plugin seems to be loading an older version of a .Net DLL that was part of another plugin installation.
I only get this error on a PC where this older plugin is installed.
I get a System.MissingMethodException at runtime. (during compilation the method is there)
I have the current version in the same folder as the rhp file.
I used reflection to see the assembly path. It shows the path in the same folder as the rhp. Still i get a method not found exception.
When starting the WPF app standalone instead of hosted in Rhino 5 it works fine.


(Dale Fugier) #2

Hi Goswin,

Can you post some code that demonstrates how you are loading the assembly?

Can I assume you are not doing something like this?

Assembly SampleAssembly;
SampleAssembly = Assembly.LoadFrom("c:\\Sample.Assembly.dll");

– Dale


#3

Hi Dale,
I just reference FSharp.Compiler.Service via Nuget. The dll gets copied into the output directory on building. (same folder as the rhp)
I am not sure how to use assem = Assembly.LoadFile(path). I tried this line but the wrong assembly seems to be loaded already. Do I have to use the methods on assem via reflection ?


(Steve Baer) #5

Rhino only allows a single assembly of a given name to be loaded in the process. When the .NET framework tells Rhino that is needs to find an assembly, Rhino walks through the list of directories where every plug-in is installed and attempts to find the DLL in that location. I’m guessing Rhino is looking in the older plug-in directory and loading the fsharp DLL from there.

I don’t currently have a good fix for this.


#6

Thanks Steve,
Can I get access to the list of directories that Rhino is walking ? For better debugging.
When I check the assembly location via reflection on one of its classes it oddly shows the correct one in the same folder as the rhp. But still the expected method is not found.


(Steve Baer) #7

Rhino.Runtime.HostUtils.GetAssemblySearchPaths should give you the list


#8

Thanks Steve,
I removed some old plugins. Now I do not see another dll of the same name in GetAssemblySearchPaths. I also used FusionLogging and did not see any other unwanted FSharp Compiler Assemblies. Still I get a method not found Exception . So the reason for this must be something else. On my Win 10 laptop everything is OK. Does RH5 on Win 7 restrict .Net plugins in any way? Is Net 4.5 supported ?


(Nathan 'jesterKing' Letwory) #9

Caveat: I work in Rhino WIP.

I have a Grasshopper plug-in written in F#. That works just fine. I’ll have to try a v6 plug-in with the F# compiler services too. Is there anything specific you are doing? Or is it already enough to just instantiate a service?


#10

Nathan, Is there a way in VS to build my plugin vor rh5 and rh6 simultaneously ?


(Steve Baer) #11

Your V5 plug-in should load into V6 as long as all of the RhinoCommon functions you call still exist in V6


(Steve Baer) #12

Maybe test with this python script to see where the fsharp assembly is coming from…

import System
assemblies = System.AppDomain.CurrentDomain.GetAssemblies()
for assembly in assemblies:
    try:
        if assembly.FullName.ToUpper().Contains("FSHARP"):
            print assembly.Location
    except:
        pass

(Nathan 'jesterKing' Letwory) #13

With some manually fiddling around in your csproj file you should be able to get configurations that support both. As Steve says the v5 RhinoCommon plug-in should load into v6 without problems, though.


#14

This is the error I get when I load it in RH6:
2017-09-08_112755
@nathanletwory I am building an FSharp scripting editor for Rhino. So I need the FSharp.Compiler.Service.dll
@stevebaer running your script does only show the desired FSharp dlls. not old ones. I tested it on another win7 PC in the office wit Rhino5. it worked fine there. So my suspicion is that the MissingMethodException is caused by something else.


(Nathan 'jesterKing' Letwory) #15

I tried in V6 a simple (empty) plug-in that instantiates an FSharpChecker.

FSharpOption<int> ps = new FSharpOption<int>(10);
FSharpOption<bool> b = new FSharpOption<bool>(false);
FSharpChecker checker = FSharpChecker.Create(ps, b, b, null);

That works just fine.

Is it possible for you to boil down to a test plug-in that does the minimal steps to reproduce the error?

/Nathan