From dd34d1160406067924861058cf8b3b4d69c16592 Mon Sep 17 00:00:00 2001 From: Alan Rynne Date: Thu, 4 Aug 2022 15:46:03 +0100 Subject: [PATCH] fix(gh): Fixed Setup.Init call on Loader.cs + added comments --- .../ConnectorGrasshopper/Loader.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ConnectorGrasshopper/ConnectorGrasshopper/Loader.cs b/ConnectorGrasshopper/ConnectorGrasshopper/Loader.cs index e7209c564a..661ac4ece8 100755 --- a/ConnectorGrasshopper/ConnectorGrasshopper/Loader.cs +++ b/ConnectorGrasshopper/ConnectorGrasshopper/Loader.cs @@ -35,16 +35,16 @@ public override GH_LoadingInstruction PriorityLoad() try { - typeof(Setup).InvokeMember( - "Init", - BindingFlags.Static | BindingFlags.InvokeMethod, - null, - null, - new object[] { version, HostApplications.Grasshopper.Slug }); + // Using reflection instead of calling `Setup.Init` to prevent loader from exploding. See comment on Catch clause. + typeof(Setup).GetMethod("Init", BindingFlags.Public | BindingFlags.Static) + .Invoke(null, new object[] { version, HostApplications.Grasshopper.Slug }); } - catch (MissingMethodException e) + catch (Exception e) { - Console.WriteLine(e); + // This is here to ensure that other older versions of core (which did not have the Setup class) don't bork our connector initialisation. + // The only way this can happen right now is if a 3rd party plugin includes the Core dll in their distribution (which they shouldn't ever do). + // Recommended practice is to assume that our connector would be installed alongside theirs. + Log.CaptureException(e); } Grasshopper.Instances.DocumentServer.DocumentAdded += CanvasCreatedEvent;