Revit应用中使用SQLite遭遇FileNotFoundException的原因排查
Hey there, let's work through why you're hitting that FileNotFoundException even after referencing SQLite DLLs and placing them in the specified directory—this is a common gotcha with Revit's add-in environment. Here are the most likely culprits:
Revit's execution directory takes priority
Revit doesn't always look in your add-in's output folder for dependencies. It often checks its own installation directory first (e.g.,C:\Program Files\Autodesk\Revit 2024). Try copying both the managedSystem.Data.SQLite.dlland the nativeSQLite.Interop.dll(critical for mixed-mode assemblies) directly into Revit's install folder. Also, double-check you're using 64-bit DLLs—Revit is 64-bit, so 32-bit SQLite files will fail silently with this error.Copy Local property isn't set correctly
In your Visual Studio project, right-click the SQLite reference and go to Properties. Make sureCopy Localis set toTrue. Even if you manually copy DLLs, if this flag is false, your build might not include them in the output when deploying the add-in. For the native interop DLL, ensure it's being copied to ax64subfolder under your add-in's directory (or directly into Revit's install folder).Add-in deployment location matters
Revit loads add-ins from specific folders like%APPDATA%\Autodesk\Revit\Addins\20XX. If your add-in is here, the SQLite DLLs need to live in the same folder as your add-in's main DLL. Relative paths can be unreliable in Revit's context, so keeping all dependencies alongside your add-in eliminates path confusion. If you're using an installer, verify it's packaging all required SQLite files (managed and native) to this location.Version mismatches or conflicting DLLs
Make sure the SQLite DLL version you're referencing matches the one you're placing. If you updated the NuGet package but didn't replace the old DLL in the target folder, a version mismatch will trigger this error. You can also use tools likeProcess Explorerto check which SQLite DLLs Revit is loading—sometimes another add-in might be loading a different version, causing a conflict.Permission restrictions block access
If you placed the DLLs in a restricted folder likeProgram Fileswithout admin rights, Revit might not have read access. Try moving the SQLite files to your add-in's folder inAppData(a non-restricted location) and test again.
内容的提问来源于stack exchange,提问作者uakam

