InvokeButton Not loading all dlls

Hello, fellow pyreviteers!
I get this error when running the .invokebutton - saying it can’t locate the Community.Toolkit.Mvvm assembly even though the file does exist in the bin folder

I have also seen this error pop up if I use the Ookii.Dialogs.Wpf.dll reference.
I was wondering if anybody had any thoughts or opinions :slight_smile:


Where are those DLLs?8 And where is the main DLL (the one that holds the logic to your tools)?

I think they need to all be in the bin folder. Although admittedly I don’t remember the difference from the lib folder and the bin folder.

If they already are there, you might have to load them from the startup script. Do you have a startup.cs or script?
In case, at some point in the Execute method (better towards the top obviously) you just load all the DLLs you need in your tools.

Something like this:

// load dependencies first
// NOTE:
// 1) we are reading the binary contents of the assembly file and loading
// from memory so Revit does not block the actuall dll file
// 2) loading of the dependendencies is required otherwise the script.cs will compile but
// will return error on execution since it can not resolve the reference to a required dll
// 3) The order of loading dependencies is actually important since they themselves have
// internal dependencies to each other e.g. Newtonsoft.Json is used in other dlls
// 4) no checks are done for dll existence so you need to improve this loop
foreach (string dependencyAssembly in new string[] {
        Path.Combine(BinPath, dependencyAssembly));

Use LoadFrom so it surely loads the correct version from the folder (this blocks the dll so it cannot overwrite)

or this:

foreach (string wbAssembly in new string[] {
        File.ReadAllBytes(Path.Combine(BinPath, wbAssembly)));

So they are not blocked and they can be overwritten while Revit is on

Note that you can also use a combination of the two methods, in case some DLLs need to be version specific and not overwritten and if others need to be overwritten and so, cannot be blocked.

Hope this helps :wink:


awesome! thanks @AndreaTas