Couchbase Error: Unable to load DLL 'CBForest-Interop'

We are trying to make following call to Couchbase Lite from “Self hosted Asp.Net Web API”. Getting following exception. Can you help us in this regard?

This is the simple call to DB we are trying to call from middleware
Plugin.Register(); //register ForestDB storage
manager = new Manager(new DirectoryInfo(@“c:\temp\db”), new ManagerOptions());

        db = manager.GetExistingDatabase(@"fusiondatastore");

We get a exception in Visual studio C# as below
"An exception of type 'System.Reflection.TargetInvocationException" occured in the mscorlib.dll but was not handled by the user code

There are a few things to try out here:

  1.   What version of Couchbase Lite are you running?
    
  2.   Can you locate the CBForest-Interop.dll file alongside your app (it should be in either the x86 or x64 folder)?
    
  3.   Do you have Visual Studio 2015 installed (or the Visual Studio 2015 C++ runtime?)
    

Jim Borden
Software Engineer
[hbase Logo]
jim.borden@couchbase.com

There are a few things to try out here: (Please find the answers below)

  1. What version of Couchbase Lite are you running?

V1.3.1

  1. Can you locate the CBForest-Interop.dll file alongside your app (it should be in either the x86 or x64 folder)?

Yes the DLL exists in both folders (x86 and x64)

  1. Do you have Visual Studio 2015 installed (or the Visual Studio 2015 C++ runtime?)

Yes I am working on VS2015 Enterprise Edition

More details on Exception:

INNER EXCEPTION: Unable to load DLL ‘CBForest-Interop’: The specified module could not be found. (Exception from HRESULT: 0x8007007E)

STACK TRACE:

at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at Couchbase.Lite.Database.OpenWithOptions(DatabaseOptions options)
at Couchbase.Lite.Manager.OpenDatabase(String name, DatabaseOptions options)
at Couchbase.Lite.Manager.GetExistingDatabase(String name)

If you run this application, what are the values of the following variables?

Environment.OSVersion.Platform
AppDomain.CurrentDomain.BaseDirectory
typeof(Plugin).Assembly.CodeBase

The first one should report as PlatformID.Win32NT and the second one is where the runtime will try to find the correct DLL file. If that is null, it will check the third one.

Environment.OSVersion.Platform
Win32NT
AppDomain.CurrentDomain.BaseDirectory
"C:\Users\E188994\documents\visual studio 2015\Projects\ConsoleApplication1\WebApiTest\"
typeof(Plugin).Assembly.CodeBase
"file:///C:/Users/E188994/documents/visual studio 2015/Projects/ConsoleApplication1/WebApiTest/bin/Couchbase.Lite.Storage.ForestDB.DLL

Looks like ASP .NET has your DLLs and such one level done from your base directory. I should probably change this to try to code base first since it seems to be more reliable, but as a workaround you can copy the applicable folder (x86 or x64 depending on your runtime architecture) to the path in BaseDirectory.