RevitToolkit icon indicating copy to clipboard operation
RevitToolkit copied to clipboard

Failed to load my project dll when using modeless dialog

Open jopi177 opened this issue 1 year ago • 7 comments

Hello!

When using a modeless wpf dialog with AsyncEventHandler my own project's dll isn't loaded when I need it in an Action given as parameter to AsyncEventHandler. The RaiseAsync() fails then. When I call a method of this dll before showing the dialog, the dll is loaded correctly.

How can I ensure, that my project's dll is loaded correctly without having to call a method of this dll before showing the modeless dialog?

Thanks in advance!

jopi177 avatar Oct 09 '24 12:10 jopi177

Hi, please provide a code example

Nice3point avatar Oct 09 '24 13:10 Nice3point

https://github.com/jopi177/SampleLoadDllToModelessWPFDialog

jopi177 avatar Oct 10 '24 14:10 jopi177

Use ExternalCommand instead of IExternalCommand. ExternalCommand ships with a dependency resolver and IExternalCommand without, so your plugin didn't recognize where it could get dependencies

Nice3point avatar Oct 10 '24 14:10 Nice3point

grafik

I've already used it...

jopi177 avatar Oct 10 '24 14:10 jopi177

Which option doesn't work? If you use the Show method, WPF creates a window in another thread and completes the ExternalCommand accordingly. You need to create ViewModel and ExternalEvent before calling Show. For example as here https://github.com/Nice3point/RevitTemplates/blob/develop/samples/SingleProjectWpfModelessApplication/RevitAddIn/ViewModels/RevitAddinViewModel.cs Create a readonly field

Nice3point avatar Oct 10 '24 14:10 Nice3point

Hi, thank you for answering so fast:)

I already do it as you recommend, create ViewModel and ExternalEvent before calling show. The difference to your sample project is, that I want to call code from the modeless dialog which is not in the same project, but in my Core.dll. This .dll can then not be loaded and I don't reach the CallTestMethod() which I want to raise in the asyncEventHandler. If I call any method of this Core.dll before Showing the dialog everything works fine (see comments in code), but this would be a very messy workaround.

jopi177 avatar Oct 10 '24 14:10 jopi177

Than try to wrap your code CallTestMethod() with ResolveHelper.BeginAssemblyResolve https://github.com/Nice3point/RevitToolkit#resolvehelper

Revit often fails to load third-party libraries, and when using the Show method instead of ShowDialog, the Toolkit scope ends when you exit ExternalCommand. ResolveHelper can help

Nice3point avatar Oct 10 '24 15:10 Nice3point