Using Sqlite dll from referenced project

Using Sqlite dll from referenced project

tpover
Contributor Contributor
509 Views
2 Replies
Message 1 of 3

Using Sqlite dll from referenced project

tpover
Contributor
Contributor

Hello everyone, 

 

I've been scratching my head for days now around this issue. I have gone through the steps in this post already: https://forums.autodesk.com/t5/revit-api-forum/my-revit-app-can-t-find-sqlite-dll/m-p/10323105

However I keep running into the same error. Here is my situation:

I am workng on a project where someone else is doing the backend part and we are using Sqlite for storing a local database. The Sqlite dll files are referenced in this backend project and copied to the Revit project assembly path. All good there, however when the actual loading happens it will throw the usual error that it cannot load the assembly. I assume that this is because Revit is also making use of its own Sqlite dll and the wrong assemblies are referenced. So I tried subscribing to the AssemblyResolve event as mentioned in the previous forum post. Then when the event hits it will ge the correct dll file, but it still throws the same error. This time with an additional inner exception about assemblied being loaded in from outside sources:

tpover_0-1705523156058.png

I followed the link it mentions and I have tried adding this to the app.config file:

<runtime>
<loadFromRemoteSources enabled="true"/>
</runtime>

 

And I have also tried creating a separate domain to load the Sqlite assembly into, like this:

 

static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
    string filename = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

    filename = Path.Combine(filename, "System.Data.SQLite.dll");

    PermissionSet trustedLoadFromRemoteSourceGrantSet = new PermissionSet(PermissionState.Unrestricted);
    AppDomainSetup trustedLoadFromRemoteSourcesSetup = new AppDomainSetup();
    trustedLoadFromRemoteSourcesSetup.ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
    AppDomain trustedRemoteLoadDomain = AppDomain.CreateDomain("Trusted LoadFromRemoteSources Domain", null, trustedLoadFromRemoteSourcesSetup, trustedLoadFromRemoteSourceGrantSet);
    Assembly assemblyRef;

    if (File.Exists(filename))
    {
        assemblyRef = Assembly.LoadFile(filename);
        trustedRemoteLoadDomain.Load(assemblyRef.FullName);
        //AppDomain.CurrentDomain.Load(filename);
    }
    return null;
}

 

Neither of the above have gotten me any further and I keep getting the same exception. 

Any help would be much appreciated.

0 Likes
510 Views
2 Replies
Replies (2)
Message 2 of 3

jeremy_tammik
Alumni
Alumni

It sounds to me as if your situation is too complex and mixed up for you to directly reference the original sqllite DLL that your other components are using. I would suggest that you find some other method to disentangle the two components. For instance, given component A that references sqllite directly, and component B that requires some of the sqllite functionality as well, you could implement appropriate methods in A that B can call to get what it needs, instead of calling sqllite itself.

  

If you want to diagnose the issues you encounter, here are some hints:

  

https://thebuildingcoder.typepad.com/blog/2021/05/revitlookup-update-fuslogvw-and-override-joins.htm...

  

For a total disentanglement solution using IPC, check out this:

  

https://thebuildingcoder.typepad.com/blog/2019/04/set-floor-level-and-use-ipc-for-disentanglement.ht...

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 3 of 3

tacoQ6N9Z
Explorer
Explorer

Thanks a lot for those links Jeremy! The second one did not yet pop up into my search results, so that's really useful! Much obliged.

 

Cheers,

Taco

0 Likes