Unable to use SQLite in VS2017 universal windows platform project - sqlite

I try to use the SQLite in the VS2017 in a universal windows platform project. I follow the guidance to download the SQLite extension for VS2015 although my local machine environment is VS2017, maybe this is the root cause? Then I add the reference with SQLIte. After that I installed the SQLitePCL with nuget.
After the SQLite installed, I wanted to try to run a demo to see if it can work right. But I found I can't using the namespace (using SQLite.Net.Attributes;) which it necessary for my demo.
I did some search about the SQLite and VS2017, But didn't found too much about such circumstances. So I want to know if anyone ever met such problem and How can your fix that?
Or it just unavailable to using SQLite in VS2017? If yes, can I complier a newest version about this?
Thanks everyone who can give me some reply or suggestion about this issue.

But I found I can't using the namespace (using SQLite.Net.Attributes;)
It seems like SQLite.Net.Attributes is belong to the Nuget package SQLite.Net-PCL, not SQLitePCL, the one you are using. SQLitePCL does't contain SQLite.Net.Attributes. You may obtain the package that is not you attempt to use.
There're many Nuget packages for SQLite, some of them are older with long time no updating. For UWP app, I'd recommend you to follow this tutorial to use a SQLite database in a UWP app.

Related

Xamarin.iOS project: CS1703: Multiple assemblies with equivalent identity have been imported

I've got a cross platform (iOS and Android) Xamarin solution using .NET Standard 2.0. The solution is being built by Visual Studio 2017 (I've tried both the current and preview versions). The Forms and Android projects build fine. However, the iOS fails to build, with the following error:
1>CSC : error CS1703: Multiple assemblies with equivalent identity have been imported: 'C:\Users\newuser.nuget\packages\system.reflection.emit\4.3.0\ref\netstandard1.1\System.Reflection.Emit.dll' and 'C:\Program Files (x86)\Microsoft Visual Studio\Preview\Enterprise\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\Xamarin.iOS\v1.0\Facades\System.Reflection.Emit.dll'. Remove one of the duplicate references.
I've tried many work arounds as described here:
oren.codes
www.hanselman.com
github.com/NuGet
Unfortunately none of these suggestions work. I have also tried to add the System.Reflection.Emit nuget package directly to the Forms and/or to the iOS projects directly. This doesn't work either. Note that originally, the The System.Reflection.Emit package wasn't referenced directly by anything in the solution. It is being pulled in by the following nuget packages which are being explicitly referenced:
Acr.DeviceInfo (5.0.5)
akavache (6.0.0-alpha0038)
AutoMapper (6.2.2)
Microsoft.Identity.Client (1.1.1-preview0040)
Newtonsoft.Json (10.0.3)
Finally, I have tried the update-package -reinstall command in the package console to reinstall all packages for the iOS project. This doesn't work either.
-- update
Just to make this clear, neither the Xamarin Forms or the Xamarin iOS project directly reference System.Reflection.Emit. That package is being pulled in as a dependency of other nuget packages, just from packages that are installed into the Xamarin Forms project. I have confirmed all of the dependencies that are referenced by Nuget, are using the same version. See these screenshots:
It seems to me that the problem (as the error says) is that there is an old version of System.Reflection.Emit that was installed by Visual Studio. However, I can't find a way of ignoring it and using the version of System.Reflection.Emit instead. As I've said above, I have tried to use a project.json file in the Xamarin.iOS project, and manually ignoring, but this doesn't work.
Does anyone else have any ideas?
As an aside, I notice that this bug is still open for Xamarin.
Xamarin Bugs
Managed to get this resolved thanks to an answer by #DirkWilhem on Xamarin Forums site.
Basically, add this to your Xamarin iOS project's .csproj file, with the other PackageReference nodes:
<PackageReference Include="System.Reflection.Emit">
<Version>4.3.0</Version>
<ExcludeAssets>all</ExcludeAssets>
</PackageReference>
Of course you need to make sure the nuget package has been added to the iOS package first.
Xamarin Forums discussion
After spending hours trying to resolve this myself I may have found a solution. Although it does feel wrong, it has got me past the issue.
Moving/Deleting the Xamarin.iOS version of System.Reflection.Emit.dll has solved the build problem for me and enabled me to deploy and run my app on a device. I don’t know what side effects it might have so will need more testing but I thought I’d share what’s worked for me so you can test it as well.
I was running on macOS Visual Studio 2017 but switched over to Windows to try and fix and first fixed on there then tried same approach on macOS and it worked as well.
On windows, go into the following directory and move the System.Reflection.Emit.dll somewhere else (you could just straight up delete it but I wanted to keep a copy I case this has some undesired effects down the track):
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\Xamarin.iOS\v1.0\Facades
On mac the following directory has it:
/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades
Like I say, it feels wrong but for now it’s got me past an issue that’s had me blocked for a couple of days so willing to just move on and hope there’s no side effects. I’d be interested to know your experience with it and if you come across anything else for the future too.
I’ll post this same comment on the Xamarin forums post (https://forums.xamarin.com/discussion/120814/xamarin-ios-project-cs1703-multiple-assemblies-with-equivalent-identity-have-been-imported) as well for future reference.
I had the same issue around a custom Nuget packages that we created and consumed in a separate project. We got around this issue by removing the automatic Nuget building checkbox in the "options" for the project. This does add the extra step of "Create Nuget Package" but one we pushed it to our Nuget repo and consumed it in our project, the errors vanished.
The problem showed up when we updated the sub-projects from PCLs to .netstandards (2.0).

Xamarin SQLite "This is the 'bait'"

I follow this guide trying to create a SQLite database to my proyect. But always got same error, doing the exactly steps of the article.
System.Exception: This is the 'bait'. You probably need to add one of the SQLitePCLRaw.bundle_* nuget packages to your platform project.
Have you added the SQLite package to all your projects? You need to add it to the app projects as well as the PCLs.
This is what the error is telling you. It uses a trick called 'bait and switch' whereby it installs a dummy assembly in the PCL with a particular interface, and in the Android and iOS apps it installs a platform specific assembly with an identical interface that actually does the interactions with the database. The idea is you code against the PCL, but at run time the platform specific version of the library is used. You can read more about this pattern at https://web.archive.org/web/20161209075521/http://log.paulbetts.org/the-bait-and-switch-pcl-trick/
Essentially though, this error is telling you that you haven't installed the NuGet package in your platform-specific projects.
I was experiencing this issue despite following the instructions in the error message and installing the missing library.
A clean & rebuild solved it
I had installed the packages (SQLite-net PCL) but I uninstalled them, then reinstalled. And then I cleaned the solution and rebuilded it and now it works.

New windows universal app with SQLite 3.8.7.4 doesn't work

I created a windows universal app (windows 8.1 and windows phone 8.1 winrt) working with SQLite 3.8.7.4.
But with SQLite, nothing works ! (The type or namespace name 'SQLite' could not be found)
YES I have included SQLite in my references :
YES I tried to clean my project and to build it again,
But I have no result. Does anyone have any idea?
I tried to update SQLite to 3.8.7.4 version on an existing app and it works, so, i continue to search why.
P.S : I'm using .NET 4.5
I found the difference between my 2 projects :
In my existing app, there are 2 files : SQlite.cs and SQLiteAsync.cs
But these files are not created on the 2nd project, that's why i can't find SQlite reference on my class.
These files are included by installing "sqlite-net" package from nugget.
In universal app if you add this 2 files : SQlite.cs and SQLiteAsync.cs in the "Shared project" then you will automatically get the reference of SQlite libraries in both project..
Refer the following link and follow the steps mention it'll help you
http://www.codeproject.com/Articles/826602/Using-SQLite-as-local-database-with-Universal-Apps
SQlite.cs and
SQLiteAsync.cs.
These two files are also missing from my project and when I try to install SQLite-net visual studio give me error that it is already installed. I spend a lot of time on finding why it is not adding these files to my project. If you are also suffering from same problem just uninstall it then reinstall it will start working.
:)

MvvmCross, SQLite, Store App?

I can get MvvmCross working with a Windows 8.0 Store App.
I can get SQLite working with a different Windows 8.0 Store App.
I cannot figure out how to get MvvmCross + SQLite working on a Store app.
I always get this Exception:
Failed to construct and initialize ViewModel for type Flux.Core.ViewModels.TestViewModel from locator MvxDefaultViewModelLocator - check MvxTrace for more information
I've spent the entire day searching with google, hoping to solve this myself. The KittenDb example is about as close as I've come, but there's no Store app example in there. (I got the Kitten example working no problem on Android.)
Is there any working example out there?
Thanks!
SQLite for Windows Store is a C++ component and comes in separate ARM, x86 and x64 binaries.
To install it, you need to add a Visual Studio extension - instructions in http://blogs.msdn.com/b/robertgreen/archive/2012/11/13/using-sqlite-in-windows-store-apps.aspx - and then reference that extension from your UI project.
To then link the correct platform version of the Cirrious.MvvmCross.Plugins.Sqlite.WindowsStore.dll assembly to your UI project, you further need to adapt your .csproj file with a <Choose> block a bit like the one in https://nuget.codeplex.com/discussions/446656
There is an open issue within MvvmCross to make SQLite easier to use from nuget (see https://github.com/MvvmCross/MvvmCross/issues/307) but I don't know if anyone is actively working on addressing this issue currently - currently users seem to be just putting up with challenges of different processor architectures and following the manual steps to adapt their projects.

Type or namespace 'Sqlite' could not be found in SQLite.cs

I have a Windows Phone 8 app that utilizes SQLite. The app has many database functions, and includes a sqlite database file which, upon running the app, is copied to the local folder and accessed. All of this worked with no problem until I first switched to release build, upon which it did not work.
I "fixed" this by deleting all NuGet references and .dll references and started over following the steps here:A Workaround to Use SQLite in a Windows Phone 8 Application
I am having a frustrating problem where, after switching from debug to release build, or vice versa, 'Sqlite' is once again no longer recognized.
I get the following errors:
The type or namespace name 'Sqlite' could not be found (are you missing a using directive or an assembly reference?)
These errors are coming from SQLite.cs, specifically these lines:
using Sqlite3 = Sqlite.Sqlite3;
using Sqlite3DatabaseHandle = Sqlite.Database;
using Sqlite3Statement = Sqlite.Statement;
How is this possible? I saw some similar questions on here, but all of them simply said to delete and re-add the references and the problem inexplicably goes away. This is not working for me.
Follow this article to configure your project. Also explained here
Second you will need to go to the GITHUB website and download the
code for SQLite-net-wp8. This is a c++ project you will need to
access a sqlite database.
Make you sure you set Conditional compilation symbols: USE_WP8_NATIVE_SQLITE and release is x86 or ARM.
Tested on VS Profesional 2013, Release build (x86, ARM)
Go thorough bellow link
Windows Phone 7 Native Database Programming via Sqlite Client for Windows Phone
Hope it will help you

Resources