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

Wayne Phipps
  • 2,019
  • 6
  • 26
  • 31
Smiley
  • 55
  • 4
  • I've done something similar in my project that referenced two different versions of the same DLL using . Have a look here: https://github.com/bzaar/DawgSharp/blob/master/DawgSharp.Verion_1_2.Benchmark/DawgSharp.Verion_1_2.Benchmark.csproj#L37 – Sergey Slepov Nov 23 '18 at 13:20

2 Answers2

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; 
    }
Sergey Slepov
  • 1,861
  • 13
  • 33
  • I am frequently switching between two versions for performing DB operation , so can loading both LiteDB version in their respective projects V_1_OperationProject and V_4_OperationProject affect on each other? E.g. 1. In V_1_OperationProject LiteDb v1 is loaded 2. Do some DB operation in V_1_OperationProject 3. Swich to V_4_OperationProject project and load LiteDB v4 4. Do some DB operation in V_4_OperationProject 5. Come back to V_1_OperationProject project and do some operation – Smiley Nov 27 '18 at 11:34
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.

Sergey Slepov
  • 1,861
  • 13
  • 33