Error: Could not load file or assembly


(Santiago Diaz Ames) #1

I’ve added a reference to a library called itextsharp (for generating PDFs) to my GHA.
When I run my add-in, it throws this error:

  1. Solution exception:Could not load file or assembly ‘itextsharp, Version=5.5.13.0, Culture=neutral, PublicKeyToken=8354ae6d2174ddca’ or one of its dependencies. The system cannot find the file specified.

The itextsharp.dll library is saved in the bin folder of my solution. I installed it via NuGet.
Did I do something wrong?


(David Rutten) #2

Is your gha loaded though memory or directly from the disk?


(Santiago Diaz Ames) #3

Hi Dave. Happy new year!
I believe it is loaded from disk.

I compile my .GHA in Visual Studio and save it in the …\AppData\Roaming\Grasshopper\Libraries folder.
Then it is loaded when Grasshopper loads, I suppose.


(David Rutten) #4

Grasshopper can load plugins in two ways, and the sequence of decisions that lead to either of these is very complicated, although the default is to load from disk. You can tell by looking at the plugin details once Grasshopper has started. Open up the About dialog, click on the little plus icon in the top left corner, double-click on your plugin icon and look at the loading details.

Other question, is the pdf dll file unblocked in Windows?


(Santiago Diaz Ames) #5

It says: “Loaded from COFF data”

Yes, the itextsharp.dll is unblocked in Windows.

By the way, I copied the itextsharp.dll to the …\AppData\Roaming\Grasshopper\Libraries folder
Now it works.

Is this the recommended solution?


(David Rutten) #6

No. Ideally you wouldn’t use COFF loading. You probably have the checkbox in the _GrasshopperDeveloperSettings command enabled. That shouldn’t be the case.

You can add an assembly attribute to your plugin informing Grasshopper how you want to load your plugin (I can’t give you an example now, on an iPad).

Or you can handle the framework assembly resolver event and load your pdf dll through code.