How to test at runtime if my dll is running inside Rhino or not?


#1

How can I test at runtime if my dll is inside Rhino or not.
Basically I want to know if I can call into the unsafeNativeMethods (like most are) of RhinoCommon.dll or not.


(Menno Deij - van Rijswijk) #2

I think that

bool Rhino.Runtime.HostUtils.RunningInRhino

should be used for this.

Unfortunately, if I run this outside Rhino it still returns true. @stevebaer may know why this is (possible bug?)

A better test is (I just found this)

if (null == RhinoApp.MainApplicationWindow)
{
    Console.WriteLine("Not running in Rhino");
}
else
{
    Console.WriteLine("Running in Rhino");
}

#3

I do it via exception handeling now in f#:

let isRhinoRunning =
    try 
        Rhino.RhinoDoc.ActiveDoc |> ignore // this line will fail if not in RH
        true
    with 
        |e -> false

(Menno Deij - van Rijswijk) #4

It depends which type of exception is thrown. An AccessViolationException can lead to instabilities and may not be caught.


#5
Rhino.Runtime.HostUtils.RunningInRhino 

works correctly for me in F# Interactive in VS.

trying to access the ActiveDoc throws

System.BadImageFormatException

or

System.TypeInitializationException

(Steve Baer) #6

How are you testing this? RunningInRhino is the correct property to check and it should be returning false when not inside the Rhino process.


(Menno Deij - van Rijswijk) #7

I copy RhinoCommon and its 8 dependencies (rhcommon_c.dll, Rhino.exe, etc.) to my output folder and run it through NUnit integrated in VS2010 by ReSharper. (I hope this make sense :smile:)

Most of the RhinoCommon functionality is available, but some give AccessViolationException.


Unit testing plug-in code with NUnit
(Steve Baer) #8

Ok; I’ll have to look into this a bit more to see how on earth this is returning true in that case.