Revit.exe directory is the key. Alternatively, use a .NET assembly resolver:
http://thebuildingcoder.typepad.com/blog/2014/05/rvtva3c-assembly-resolver.html
Cheers,
Jeremy
Hi Jeremy,
i have the same problem. I try use Assembly.LoadFrom(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "System.Data.SQLite.dll")); but don't working.
I have the same problem. My plugin program run on Revit 2021. I make sure that Revit 2021 have not 'System.Data.SQLite.dll'. I don't know why tell me 'cannot load the dll'.
I haved try using 'Linq2Db' and 'EntityFramework' for sqlite to do, but I failed. If you have solution, please tell me.
Thinks!
try read what path it give you back before calling dll.
The dll path is valid. I guess that revit maybe not work well. My solution: Dapper+System.Data.SQLite.Core+DapperExtensions. You will can write lambda expression to do anything.
Demo: https://github.com/kelicto/HelloDapper. EntityFramework and Linq2Db cannot do that and throw exception.
I ran into issues recently in 2022 related to references that previously worked and turning on and using the Fusion Assembly Binding log viewer was a substantial help.
"Fuslogvw.exe (Assembly Binding Log Viewer) | Microsoft Docs" https://docs.microsoft.com/en-us/dotnet/framework/tools/fuslogvw-exe-assembly-binding-log-viewer
SQlite is dependent on these two .net binaries that Revit does not load, therefore they also need to be loaded along with it:
Microsoft.WindowsAPICodePack.dll
Microsoft.WindowsAPICodePack.Shell.dll
Maybe you are right. But why don't auto load them? 'Assembly.LoadFrom' method can auto load all required dlls. And the sqlite should give us all dlls.
What we're doing is API programming, unlike creating a standlone program there is no auto Loading and Revit is not going to load a single assembly unless explicitly told to do so. When loading assemblies I'm careful to examine what has already been loaded in order to avoid double loading and creating a memory leak.
See if you can make sense of the below code, to get my meaning..
And do you have a link to the demo.
if (AppDomain.CurrentDomain.GetAssemblies().Where(x => x.FullName == stringWindowsAPICodePack).Count() == 0)
{
Assembly.Load(File.ReadAllBytes(path + "\\Microsoft.WindowsAPICodePack.dll"));
}
if (AppDomain.CurrentDomain.GetAssemblies().Where(x => x.FullName == stringWindowsAPICodePackShell).Count() == 0)
{
Assembly.Load(File.ReadAllBytes(path + "\\Microsoft.WindowsAPICodePack.Shell.dll"));
}
//2 August 2019: End.
Properties.Settings.Default.AssemblyNeedLoading = false;
Properties.Settings.Default.Save();
Hello @joshua.lumley ,
Thanks for your great answer it helped me a lot.
Could you tell me which using you need for the following snippet, and why it is needed? It seem to be working without.
Properties.Settings.Default.AssemblyNeedLoading = false;
Properties.Settings.Default.Save();
Best regards,
François R
This code is in the IExternalCommand interface (when the user clicks a button) and only needs to be run once per session. The AssemblyNeedLoading variable is set to true on launch.