LiteDB- How to add 2 DLL of LiteDB in two different project but they are referenced by one Main project

1

I have created 3 projects:

  1. V_1_OperationProject:
    (Class library project)To handle operation on LiteDb version 1
  2. V_4_OperationProject :
    (Class library project)To handle operation on LiteDb version 4
  3. MainProject:
    Gives the calls to methods in V_1_OperationProject and V_4_OperationProject project

V_1_OperationProject contains logic to open and inset into DB file created from LiteDB v1 dll and similarly with V_4_OperationProject.

When I am going to insert values in DB from V_1_OperationProject, I am getting following exception:

System.IO.FileLoadException: 'Could not load file or assembly 'LiteDB, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)'

When I have removed V_4_OperationProject and its associated DLL then it got started working. But I want both to work.

So I have tried adding following in main project:

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="LiteDB"
                          publicKeyToken="4ee40123013c9f27"
                          culture="neutral" />
        <bindingRedirect oldVersion="0.0.0-1.0.0" newVersion="1.0.0" />
        <bindingRedirect oldVersion="1.0.1-4.0.0" newVersion="4.0.0" />
        <codeBase version="1.0.0" href="\LiteDB-1\LiteDB.dll" />
        <codeBase version="4.0.0" href="\LiteDB-4\LiteDB.dll" />
      </dependentAssembly>
    </assemblyBinding>

This is also not working for me. Can anyone please help me in this?? Thanks in Advance

c#
dll
litedb
asked on Stack Overflow Nov 23, 2018 by Smiley • edited Nov 23, 2018 by Wayne Phipps

2 Answers

0

You need to tell the runtime where to look for each version. You can do so using AssemblyResolve:

        AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
    }

    static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
    {
        if (args.Name == "LiteDB, Version=1.1.1.0, Culture=neutral, PublicKeyToken=null")
        {
            return Assembly.LoadFrom(@"..\..\..\packages\LiteDB.1.1.1\lib\net\LiteDB.dll");
        }

        // The most recent version will be copied to the output directory.
        // Use the normal resolution mechanism to locate it.
        return null; 
    }
answered on Stack Overflow Nov 23, 2018 by Sergey Slepov
0

The two LiteDB versions will have separate code and data. But there might be other ways for them to clash like sharing a common config, port numbers or whatever. I guess you will have to try and see if it works for you.

answered on Stack Overflow Nov 27, 2018 by Sergey Slepov

User contributions licensed under CC BY-SA 3.0