WP8 SQLite error: The specified module could not be found - c#

I'm trying access a SQLite database from my Windows Phone 8 app but am encountering the following error whenever SQLite code is hit:
{System.IO.FileNotFoundException: The specified module could not be found. (Exception from HRESULT: 0x8007007E)
at System.StubHelpers.StubHelpers.GetWinRTFactoryObject(IntPtr pCPCMD)
at Sqlite.Sqlite3.sqlite3_open_v2(String filename, Database& db, Int32 flags, String zVfs)
at SQLite.SQLite3.Open(String filename, Database& db, Int32 flags, IntPtr zVfs)
at SQLite.SQLiteConnection..ctor(String databasePath, SQLiteOpenFlags openFlags, Boolean storeDateTimeAsTicks)
at TopoMap.Map.MapTileServer.<Initialise>d__0.MoveNext()}
I've installed the Visual Studio extension SQLite for Windows Phone (v3.8.4.3).
I've installed the sqlite-net-wp8 NuGet package (v3.8.4.3).
I've added SQLite.cs and SQLiteAsync.cs to my project.
I've added the USE_WP8_NATIVE_SQLITE conditional compilation symbol to my project.
The project runs fine with no issues until a line of code is hit that accesses the underlying Sqlite3 class.
Any ideas what the issue might be?

Delete all references to sqlite from solution
Install Sqlite for WP8 from http://visualstudiogallery.msdn.microsoft.com/cd120b42-30f4-446e-8287-45387a4f40b7
Restart Visual Studio. In my case it's Visual Studio 2013.
open your solution where you want to use sqlite
Using package manager console in order to install sqlite-net. Enter the following command: Install-package sqlite-net
Install sqlite-net-wp8. Enter the following command: Install-package sqlite-net-wp8
Add compilation cofiguration
7.1 Right-click the project and select Properties.
7.2 Select the Build tab.
7.3 In the Configuration list, select All Configurations.
7.4 In the Platform list, select All Platforms.
7.5 On the Build tab, you’ll see Conditional compilation symbols under the General header, containing a default value of SILVERLIGHT;WINDOWS_PHONE on a Windows Phone app project. Change the value to SILVERLIGHT;WINDOWS_PHONE;USE_WP8_NATIVE_SQLITE and save the project file.
Right-click References and select add reference.Go to Windows Phone -> Extensions and check the option SQlite for Windows Phone
It works for me!!
Good luck

Related

Xamarin.UITesting NU1201 Error: Android 8.1 Is incompatible with .NETFramework 4.6.1

Have been having a little issue for the last couple of days now where I will create a new Xamarin Forms project on Visual Studio 2017 and add a Xamarin.UITest Cross-Platform Test Project for unit testing I recieve a series of NU1201 Errors when I reference the .Android App in the UITest Project.
Here is the exact error i get:
Error NU1201 Project App1.Android is not compatible with net461 (.NETFramework,Version=v4.6.1) / win-x64. Project App1.Android supports: monoandroid81 (MonoAndroid,Version=v8.1)
I have played around with the Android version numbers to see if the UITesting package doesnt support the latest android but no matter what version of android i target the problem remains the same.
Here is a screenshot of the project.
All the code is unchanged from the default project and runs in the simulator fine but only produces these errors when the Android app is referenced to the UITest project.
Solved it after many more hours of testing and trialling. Instead of adding the Android project to the references, Within the AppInitializer I added another method to the StartApp() call like so:
public class AppInitializer
{
public static IApp StartApp(Platform platform)
{
if (platform == Platform.Android)
{
return ConfigureApp.Android.InstalledApp("com.companyname.App1").StartApp();
}
return ConfigureApp.iOS.StartApp();
}
}
Therefore once I had already run the app via the emulator for the first time and installed on the device, the UITest simply uses the installed APK on the emulator instead of the project.
For those who ran into error NU1201, you might have come to the right place. This may not apply to the question asked but I ran into error NU1201 the other day and the reason for that is the nuproj configuration file for our nuget project has target configuration wrong. It should have been
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
instead of
<TargetFramework>net462</TargetFramework>
because the project is not of "SDK-style."
References: https://learn.microsoft.com/en-us/visualstudio/msbuild/msbuild-target-framework-and-target-platform?view=vs-2019

How to use iOS simulator/Android simulator from visual studio for Mac with xamarian.forms

I made mobile app at azure and quickstarted it as xamarian.forms and (after failing to publish downloaded table api application and deciding to edit it in browser) downloaded the client application they provided. Then when I tried to launch it with on (Debug>IPhone 8 Plus iOS 11.2) simulator, it (simulator) started but no application is visible (and nothing unusual is installed).
It shows warnings (could it be relevant?):
Warning MSB3276: Found conflicts between different versions of the same dependent assembly. Please set the "AutoGenerateBindingRedirects" property to true in the project file. For more information, see http://go.microsoft.com/fwlink/?LinkId=294190. (MSB3276)
(For Android simulator it gives some error like:
/Library/Frameworks/Mono.framework/Versions/5.4.1/lib/mono/xbuild/Microsoft/NuGet/Microsoft.NuGet.targets(5,5): Error: Your project is not referencing the "MonoAndroid,Version=v8.0" framework. Add a reference to "MonoAndroid,Version=v8.0" in the "frameworks" section of your project.json, and then re-run NuGet restore.
)
How can I see the ****** application?
Thank you. =)
Open the project.json file in your xxx.Droid project. Change the MonoAndroid version from:
"frameworks": {
"MonoAndroid,Version=v7.1": {}
}
to:
"frameworks": {
"MonoAndroid,Version=v8.0": {}
}
Now, Restore Nuget Packages for your solution.

SQLite UWP Error with Mobile EMulator Windows 10

I am getting the following error when I run the Mobile Emulator while trying to compile and run a VS 2015 UWP app. The app runs fine when using the Local Machine or Simulator.
System.TypeInitializationException was unhandled by user code
HResult=-2146233036
Message=The type initializer for 'SQLitePCL.raw' threw an exception.
Source=SQLitePCL.raw
TypeName=SQLitePCL.raw
StackTrace:
at SQLitePCL.raw.sqlite3_open_v2(String filename, sqlite3& db, Int32 flags, String vfs)
at SQLite.SQLiteConnection..ctor(String databasePath, SQLiteOpenFlags openFlags, Boolean storeDateTimeAsTicks)
at SQLite.SQLiteConnection..ctor(String databasePath, Boolean storeDateTimeAsTicks)
at App3.MainPage.LoadSQLData()
at App3.MainPage..ctor()
at App3.App3_XamlTypeInfo.XamlTypeInfoProvider.Activate_0_MainPage()
at App3.App3_XamlTypeInfo.XamlUserType.ActivateInstance()
InnerException:
HResult=-2146233052
Message=Unable to load DLL 'sqlite3': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
Source=SQLitePCL.raw
TypeName=""
StackTrace:
at SQLitePCL.SQLite3Provider.NativeMethods.sqlite3_win32_set_directory(UInt32 directoryType, String directoryPath)
at SQLitePCL.SQLite3Provider..ctor()
at SQLitePCL.raw..cctor()
I have the following references:
SQLite for Universal Windows 3.9.1
sqlite-net-pcl
Microsoft Visual C++ 2013 Runtime Package for Universal Windows
The code where the error occurs in the "using (var db......:
int recCtr = 0;
var root = Windows.Storage.ApplicationData.Current.LocalFolder.Path;
var dbPath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "BaseBallOU.db");
List<string> NHLCollection = new List<string>();
using (var db = new SQLite.SQLiteConnection(dbPath))
{
var NHLlist = db.Table<Teams>().ToList();
foreach (var item in NHLlist)
{
recCtr++;
NHLCollection.Add(item.TeamName.ToString());
}
}
I see a number of similar posts, but some are dated and not using the most recent SQLite libs and pcls.
I'm looking for the correct SQLite dlls, sqlite pcls, runtimes (e.g. VC++ 2013? And version numbers that can be used to compile and run a UWP app on both the local machine and phone emulator.
TIA
Following is how I work with SQLite:
Download and install Sqlite visual studio extension from http://sqlite.org/download.html
Create a new blank c# Universal Windows Platform app.
Right click on the References of project -> Add Reference -> Universal Windows -> Extension -> add SQLite for Universal App Platform and its dependency Visual C++ 2015 Runtime for Universal Windows
Right click on the project node -> Manage NuGet packages -> Search SQLite.Net-PCL -> Install the default version 3.0.5
Change your code to the following:
using (var db = new SQLite.Net.SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), dbPath))
{
...
}
Step 1: Install SQLite VSIX pacakge for Universal Windows Platform development using Visual Studio 2015
https://www.sqlite.org/2016/sqlite-uwp-3130000.vsix
Step 2: Install NuGet package SQLite.NET-PCL
PM> Install-Package SQLite.NET-PCL
Step 3: Add references
Add Reference -> Universal Windows ->Extensions -> Make sure the following packages have been checked:
"SQLite for Universal Windows Platform"
"Visual C++ 2015 Runtime for Universal Windows Platform Apps"
If you didn't add reference for VC++ 2015 Runtime, you will get an error mentioned that "Unable to load DLL 'sqlite3' in SQLite Net Platform WinRT" when creating DB connection.

Could not load file or assembly 'Microsoft.SqlServer.DTSRuntimeWrap

I made a SSIS package that would export data to msaccess. If i try to run the package on its solution project it will execute without error. But when I call the package inside my program, I will get an error
Could not load file or assembly 'Microsoft.SqlServer.DTSRuntimeWrap, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91'. This assembly was compiled for a different processor.
Here is my code:
public void RunPackage()
{
textstring("Locating Package...");
m_worker2.ReportProgress(20);
string PkgLocation;
Package pkg;
Microsoft.SqlServer.Dts.Runtime.Application _app = new Microsoft.SqlServer.Dts.Runtime.Application(); --> I got an exception here.
DTSExecResult pkgResult;
PkgLocation = Properties.Settings.Default.PackageLoc + "\"Package1.dtsx";
textstring("Loading Package...");
m_worker2.ReportProgress(30);
pkg = _app.LoadPackage(PkgLocation, null);
textstring("Executing Package...");
m_worker2.ReportProgress(30);
pkgResult = pkg.Execute();
textstring("Finished...");
m_worker2.ReportProgress(30);
textstring(pkgResult.ToString());
m_worker2.ReportProgress(30);
}
Can anyone point me out the right way. I don't know what is meant by that error. Please enlighten me?
That means, that you mixed x86 and x64 architectures. If your application is x86 (=32 Bit) architecture, you can not use x64 (=64 Bit) compiled assemblies. Try to compile your application with Any CPU or x64.
From MSDN:
To set the Platform target property (C#)
With a project selected in Solution Explorer, on the Project menu,
click Properties.
Click the Build tab.
Choose a CPU type from the Platform target list. The options are Any
CPU (the default), x86, x64, and Itanium.
Here is the complete Link: How to: Optimize an Application for a Specific CPU Type
Important: if you compile for x64 and use x64 assemblies, your application will not run under 32-Bit versions of Windows.
I recently upgraded to SQL 2016 and my VB app stopped running my package. I saved the package no problem to SQL 2016. VB wouldn't run it via the LoadFromSqlServer method. Just reported Could not load file or assembly 'Microsoft.SqlServer.DTSRuntimeWrap' What fixed it for me was to delete the old 12.0 manageddts reference and adding the new 13.0 reference (see image)
Depending on your version of SQL Server Data Tools that is installed on your system, you must add a specific version of Microsoft.SqlServer.DTSRuntimeWrap in your C# Application.
For example if you have SQL Server Data Tools 2010 installed you must add Microsoft.SqlServer.DTSRuntimeWrap 11.0.0.0, and for SQL Server Data Tools 2012
you must add Microsoft.SqlServer.DTSRuntimeWrap 12.0.0.0

Beginner ILNumerics: install under VS2012

I am very much interested in ILNUmerics and would like to try the free version, but I am having troubles.
I have started with a console application and was trying to run the 'hello ilnumerics'console application but I noticed that VS fails to find MKL libraries.
I am using VS2012 under Windwos 8 (through Bootcamp on a MacBook Pro mid 2010; should it be relevant); I have installed the NuGet Packages extension from the Project solution. Then right-click on references in the solution explorer, 'Manage Nu Get Packages', fron online/search found ilnumerics in various versions. I chose 'ILNumerics' and install. I got 'ILNumerics' and 'ILNumerics.Native' added to my project. Then I can see ILNumerics under 'References' in Solution Explorer and also get two new folders /bin32/ and /bin64/ they both contain two DLLs named: libiomp5md.dll and mkl_custom.dll. I have checked their
'Copy to Ouput Directory' property and they are all set to 'Copy if newer'.
Apparently mkl_custom is not found. I write the following code, taken from the quickstart guide:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ILNumerics;
namespace ConsoleApplication3
{
class Program : ILMath
{
static void Main(string[] args)
{
ILArray<double> A = array<double>
(new double[] { 1,1,1,1,1,2,3,4,1,3,6,10,1,4,10,20} ,4, 4);
ILArray<double> B = counter(4, 2);
ILArray<double> Result = linsolve(A, B);
Console.Out.WriteLine("A: " + Environment.NewLine +
A.ToString());
Console.Out.WriteLine("B: " + Environment.NewLine + B.ToString());
Console.ReadKey();
}
}
}
and I get this exception:
An unhandled exception of type 'System.DllNotFoundException' occurred in ILNumerics.dll
Additional information: Unable to load DLL 'mkl_custom': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
If I do not invoke linsolve the ToString method of ILArray does work: if I comment // ILArray Result = linsolve(A, B);
I get the two matrices printed on the screen.
I have also tried to compute the determinant of a matrix and got the same exception: apparently any time I call mkl_custom VS is not capable to find it.
Any help/hint, please?
Also, is it necessary to install ILNumerics through NuGet on any project added to the solution? Would it be possible to install it locally once for all and then add the reference if necessary?
Two options:
1) Make sure, all binaries are accesible as intended: ILNumerics uses AnyCPU targets and chooses the platform dependend subfolder by adding the "bin32" / "bin64" directories to the PATH envoronment variable on startup. Possibly there is something failing on your machine? You can make sure by placing the correct binaries (depending on your platform) directly into the output path manually.
2) In case the error persists: mkl_custom.dll depends on some other dlls itself. One (libiomp5md.dll) is delivered with the ILNumerics nuget package. Others are expected to exist on your system: KERNEL32.DLL and MSVCR110.DLL. Make sure, you have these! If the kernel dll was missing -> call it a miracle and reinstall your system. If the msvcr110 is missing -> go here and install the "Visual C++ Redistributable for Visual Studio 2012".
In case the problem persists, you may file a bug on the ILNumerics bugtracker, because, the runtime should be there, as you wrote you are using VS2012. Possibly it is a versioning problem though.
EDIT: Since version 4.0 ILNumerics does not deploy the native binaries in bin32/ bin64/ subfolder anymore but installs all native dependencies systemwide into the GAC and System32/WOW folders. The old scheme will still work (for compatibility with old projects) though. But it is not necessary anymore to deal with any dependancies for ILNumerics explicitly. They should simply be found at runtime.
Like numbers303 said, ILNumerics.dll can't find a required dependency. You can brute force fixing this dependency by copying the required DLLs to the same directory as the ILNumerics.dll as a post build step, but I think there's a more elegant solution.
A VS2010 .NET console solution gets created by default with the x86 configuration. Compiling and running the ILNumerics example Hello ILNumerics! code with this configuration results in a DLL not found exception (mkl_custom.dll).
Re-targeting the solution via configuration manager to 'Any CPU' fixed the issue for me:
In Solution Explorer, right click on the solution and select properties. Select Configuration Properties and click on the Configuration Manager... button in the upper right hand corner. Make sure that the project that uses ILNumerics has the 'Any CPU' selected. If 'Any CPU' isn't available as a selection, select '' from the pulldown and create an 'Any CPU' platform based on your current platform. Usually this just means accepting the default in the 'New Project Platform' dialog. You'll probably also want to modify the 'Active solution platform:' to contain an 'Any CPU' target as well.
Rebuild/run.
In my case it helped to install "Visual C++ Redistributable for Visual Studio 2012" although I work with Visual Studio 2010 with the corresponding "Visual C++ Redistributable for Visual Studio 2010" installed. Which worked fine as long as the mkl_custom.dll is not needed. But colleagues of mine dosn't have this problem without having the 2012 Redistributable installed.

Categories