ericsink / SQLitePCL.raw

A Portable Class Library (PCL) for low-level (raw) access to SQLite
Apache License 2.0
533 stars 109 forks source link

'The type initializer for SQLitePCL.raw threw an exception' in windows phone 8.1 silverlight app #87

Closed pragnagopa closed 8 years ago

pragnagopa commented 8 years ago

SQLitePCL.Raw reference does not show up in references for windows phone 8.1 silverlight app. Adding reference to VC++ runtime package did not help. Invoking any operations fail with error: 'The type initializer for SQLitePCL.raw threw an exception'

ericsink commented 8 years ago

WP8/8.1 silverlight is odd because it does not support pinvoke, so the access to SQLite must go through C++/CLI, which affects the build. The reference is not visible in the references section of the project. And you cannot build for Any CPU.

Try building for x86 instead and see if it works, even though SQLitePCL.raw will still not show up in the references.

pragnagopa commented 8 years ago

Building for x86 dint help. Same error.

ericsink commented 8 years ago

I need more details from you. Which of the SQLitePCL nuget packages are installed? What versions? What sqlite wrapper are you using? Are you calling raw.SetProvider()? etc.

pragnagopa commented 8 years ago

Thank you for quick follow up.

I am currently investigating moving to SQLitePCL.raw: issue to replace SQLitePCL in Azure Mobile Apps .Net SDK. Using SQLitePCL.raw version: 0.9.3 nuget package directly on all the platforms we support works except for Windows Phone silverlight apps.

I am not calling raw.SetProvider(). Let me know if this is required for Windows Phone 8.1 Silver light Apps.

ericsink commented 8 years ago

Have you added the SQLitePCL.native.sqlite3.v110_wp80 nuget package? You need this.

You should not need to call SetProvider(), nor should you need the VC++ runtime extension SDK.

I just verified this is working for me with a new Windows Phone Silverlight 8.1 blank app in VS 2015.

pragnagopa commented 8 years ago

Thanks. Adding SQLitePCL.native.sqlite3.v110_wp80 package fixed it.

ericsink commented 8 years ago

FWIW:

When I shipped 0.9.x, I broke Windows Phone SilverLight support (unintentionally).

Most of the people who noticed this were using sqlite-net-pcl.

In 0.9.3, which just shipped last week, I fixed Windows Phone Silverlight support, which included the addition of the SQLitePCL.native.sqlite3.v110_wp80 package.

The information about this required dependency is handled by SQLitePCL.bundle_green, upon which sqlite-net-pcl has a dependency.

But this stuff needs to be documented as well, because currently only sqlite-net-pcl depends on SQLitePCL.bundle_green, and I had not gotten around to updating the README and such. :-(

pragnagopa commented 8 years ago

SQLitePCL.bundle_green looks like a good fit for our SDK as well. I will look into adding this package as dependency to Azure Mobile Apps manged SDK.

ericsink commented 8 years ago

A bit more background about bundle_green:

In version 0.9.x, I reorganized the nuget packages with more of an emphasis on power and flexibility, at the expense of ease of use. All past attempts to make this really easy would invariably fail to handle somebody's use case. So I redesigned some things in 0.9 to make it possible to handle every use case I knew about, even if that meant more nuget packages and, in some cases, the need to call an initialization function.

bundle_green is simply an "ease of use" wrapper, little more than a collection of settings. Its basic purpose is to provide a "batteries included" experience for sqlite-net-pcl users.

But it does this by removing flexibility. It is making decisions that may not be correct for everyone. For example, bundle_green assumes that 'net45' means 'Windows desktop', but that assumption would be very wrong for Couchbase Lite, which is why those folks don't use bundle_green.

The reason I put the word 'green' in the name of this package is that I anticipate needing more of these bundles, so I want them to have different names. I want to stay out of the business of trying to find one set of defaults/settings/dependencies that will suit everyone. Instead, I would rather just have multiple bundles, each of which is a collection of settings that are tuned for one downstream package.

Bottom line: I would be happy to build and maintain a bundle package specifically for your use. In fact, unless we are certain that your requirements will always be the same as those of sqlite-net-pcl, I might even prefer that path. This preserves my ability to change the settings of bundle_green as needed to minimize problems for that user base without worrying about breaking anything for your user base.

Alternatively, you can do what the Couchbase Lite folks do and manage the dependencies and initialization yourself.

Or you can use bundle_green for now and change it later if requirements diverge.

Your choice. I just wanted to give more context. I am available to help in any way I can.

pragnagopa commented 8 years ago

Thanks! For now, the requirements are similar to sqlite-net-pcl. Will contact you if that changes.

pragnagopa commented 8 years ago

We will be adding support for .Net standard soon. Can you please let me know if there is a plan to add NetStandard soon? If yes, which version?

ericsink commented 8 years ago

Yes, I've been taking a look at netstandard support.

When you say "which version", do you mean "which version of netstandard"? If so, I'm not certain, but I currently support everything back to .NET 3.5, so in general, SQLitePCL.raw isn't very demanding of its .NET stack.