Obtuse problems with Windows Phone

So a user reported to me that Windows Phone running anything older than the very latest version of Windows 10 would fail to do anything with Couchbase Lite.  The exception being thrown was DllNotFoundException.  This particular exception is ridiculous because what it actually means is “cannot find a native DLL, or one of the native DLLs it depends on.”  So what was the offending DLL in this case?  Let’s analyze!

I know it was not LiteCore.dll itself, since the builds worked fine on the newest Windows Phone emulator.  However, as soon as I ran with an older one the problem happened immediately and every time.  So I used the wonderful program Dependency Walker to analyze what LiteCore.dll depends on to see if anything there looked suspicious.  Nothing suspicious there, just regular things like kernel32.dll, the C++ runtime, sqlite3, etc.  Nothing suspicious right?  So I thought…

I was browsing the documentation for the LoadPackagedLibrary function when I saw an interesting note near the bottom.

Note  On Windows Phone, LoadPackagedLibrary must be called from
 PhoneAppModelHost.dll. Using Kernel32.dll is not supported.

Soooo…possibly I can’t use kernel32.dll?  Well actually I’m not directly using it anywhere, so why does LiteCore.dll think that it needs it?  I’m not sure if this is an issue with CMake, which I use to generate the Visual Studio projects, or what but kernel32.dll, among others, get linked by default without you having to do anything.  So actually what I needed was a way to stop this behavior.

There are settings in Visual Studio to “ignore default libraries (all)” or “ignore default libraries (specific)”.  Ignoring all default libs causing too many errors to sift through so in the end I had to ignore kernel32.dll, and ole32.dll.  After that things magically began to work!  I wish I knew why I had to flail so much to realize this though…


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s