How can I add SQLite3.dll to my Project? - c#

I'm building an WPF C# Application with an embedded SQLite Database.
But when I debug it I always get an exception of type 'SQLite.SQLiteException'.
using System.Collections.Generic;
using System.Linq;
using SQLite;
using System.Collections;
namespace SheepMaster
{
class SheepDao : IEnumerable
{
private List<Sheep> sheeps { get; set; }
private SQLiteConnection con = new SQLiteConnection("sheeps.db");
public SheepDao()
{
con.CreateTable<Sheep>();
sheeps = con.Table<Sheep>().ToList();
}
public IEnumerator GetEnumerator()
{
return sheeps.GetEnumerator();
}
public void add(Sheep value)
{
sheeps.Add(value);
}
}
}
When I try to install sqlite from nuget I am getting the following error message:
Could not install package 'sqlite.redist 3.8.4.2'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.6', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
and when I manually install it I get this message:
A reference to path could not be added...
System.Data.SQLite
I installed it trought nuget but it didn't change anything.

Either download and install sqlite3.dll from: http://sqlite.org/download.html
or Find on nuget package SQLite v3.13.

Related

C# .NET Framework 4.8 Class library can't load Bitmap from System.Drawing

My .net Frameowkr Class Library runs on version 4.8, System Drawing reference is Version 4 and System.Drawing.Common is Version 7.
Here is a minimal working prototype:
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestBMP
{
public class Class1
{
public Class1() {
var bitmap = new Bitmap(1000, 2000, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
Console.WriteLine("Test");
}
public String hello()
{
return "Hello";
}
}
}
I'm placing a notebook inside the release folder with the following python code to test the library:
from pythonnet import load
load("coreclr")
import clr
clr.AddReference("TestBMP")
from TestBMP import Class1
obj = Class1()
Already there im getting, similar to my main project, this error:
Could not load type 'System.Drawing.Bitmap' from assembly 'System.Drawing, Version=4.0.0.0, Culture=neutral
I have scanned ever single link on google, but all just recommended to add the reference of System.Drawing.Common... I've done that and its also in the release folder of the project. I have also tried different .NET Framework versions without success.

Error when getting a UWP package info from a Winform App?

Using a WinForm App, I'm trying to mimic this sample from Microsoft's Github site that shows how to get package info by using the Windows Runtime packaging API.
I'm getting following error at line: Package package = Package.Current;, of the code below, when trying to get a UWP package info from a WinForm app:
The type or namespace name 'Package' could not be found (are you missing a using directive or an assembly reference?)
Question: Although the error is a famous C# error that has many online posts/solutions, but here the context is different. Compiler seems to be complaining that I'm missing required assembly for Package class. But I do have using Windows.ApplicationModel; using statement in my code below. So what may be a possible cause of the error; i.e. what I may be missing here?
NOTE: To ensure the inclusion of the required assemblies, I did install this UWPDesktop NuGet package in WinForm Project on VS2017-ver 15.9.5 on Windows 10 Pro - Ver 8109:
WinForm App: Relevant code that throws error at line: Package package = Package.Current;
using System;
using System.Windows.Forms;
using Windows.ApplicationModel; //I added from here
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
using Windows.ApplicationModel.Background;
using Windows.Foundation.Collections;
using Windows.Storage;
using Windows.Storage.Search;
using Windows.UI.Xaml;
using Windows.Management.Deployment;
namespace WinForms_to_UWP
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Package package = Package.Current;
PackageId packageId = package.Id;
Console.WriteLine(packageId.FullName);
}
}
}
From the GitHub's UWP Sample project: The relevant Code from scenario1_identity.xaml.cs that WORKS fine:
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
using SDKTemplate;
using System;
using Windows.ApplicationModel;
namespace SDKTemplate
{
void GetPackage_Click(Object sender, RoutedEventArgs e)
{
Package package = Package.Current;
PackageId packageId = package.Id;
String output = String.Format("Name: \"{0}\"\n" + packageId.FullName);
OutputTextBlock.Text = output;
}
UPDATE:
Also worth noticing that when adding Using Windows..... statements on the top, the VS intellisense recognized only Window.Foundation and Window.UI. statements. For other Using Windows..... statements I had to hardcode - for example, Windows.ApplicationModel;. However VS2017 did not complain when I hard coded them. Moreover, all Using statements starting with Windows. are grayed out as shown in image below. Not sure if it has anything to do with the error:
The Nuget package you are referencing is outdated I am afraid and may not be maintained anymore.
But the problem is easy to fix. Just add a reference to the windows.winmd file of the SDK version you are targeting. See this screenshot:

Microsoft.ProjectServer.Client dll is missing

I'm trying to generate lookup tables in SharePoint and taking reference from a sample project. Here is the code snippet I'm referring to:
using Microsoft.SharePoint.Client;
using Microsoft.ProjectServer.Client;
using System.Security;
using System.Configuration;
namespace PWA_CSOM
{
public partial class FinalLogic_Second : System.Windows.Forms.Form
{
#region veriables
private static ProjectContext projContext;
string pwaPath = "";
string userId = "";
string userPassword = "";
}
}
I have created a new project and created a variable to type ProjectContext, however I'm not able to find the reference for it. I have tried everywhere but no luck:
using Microsoft.ProjectServer.Client; //Missing Reference
namespace LookupTable
{
public static class Infrastructure
{
#region Properties
public ProjectContext project;
#endregion
}
}
I tried Local Assembly Reference but no luck -
Also tried the Nuget Reference -
Is there something missed from my end? Any help is appreciated.
Install SharePoint Online CSOM package in Package Manager Console in Visual studio.
Install-Package Microsoft.SharePointOnline.CSOM -Version 16.1.7723.1200
https://www.nuget.org/packages/Microsoft.SharePointOnline.CSOM
If you have already installed Project Server you can do this.
As mentioned Here ,
You can reference to this library again by just going into this path and select the dll file.
%ProgramFiles%\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.ProjectServer.Client.dll

EntityFrameworkCore.PostgreSQL Transform point

Is there a way to Transform a point to another SRID using EntityFrameworkCore?
previously I used ST_Transform(ST_GeomFromText(#coord,4326),32661)
My current code looks like this
var postgisGeometry = new PostgisPoint(lon, lat) {SRID = 4326};
The SRID of the coord is 4326 and needs to become 32661
This is done for backwards compatibility reasons and there is no option converting the database to another SRID
Is there a geometry library or a PostGIS EntityFrameworkCore method to transform a point to another SRID
The release version Npgsql.EntityFrameworkCore.PostgreSQL Entity Framework Core provider for PostgreSQL does not support spatial types.
The good news is that spatial types support and support for some spatial operations SQL translations are already available as a pre-release candidate.
If you want to use these libraries, you need to also use the pre-realease candidate version of Entify Framework Core.
First, uninstall your existing entity framework or npgsql packages.
One of the packages needed (GeoAPI) is not available in the standard NuGet source so we are gonna use the myget.org source.
To use it, you need to add a new NuGet source in Visual Studio by going to Tools -> Options -> NuGet Package Manager -> Packages Sources
Create a new source and name it myget.org and use the following URL in the source text field:
https://www.myget.org/F/imageprocessor/api/v3/index.json
Remember to click on update to save the changes, otherwise they are not saved (weird, I know).
To add the required packages, use the Package Manager Console (View -> Other Windows -> Package Manager Console) and select myget.org from the Package Source drop down, then, execute the following commands:
Install-Package Microsoft.EntityFrameworkCore -Version 2.1.0-rc1-final
Install-Package GeoAPI -Version 1.7.5-pre024
Install-Package Npgsql -Version 4.0.0-rc1
Install-Package Npgsql.EntityFrameworkCore.PostgreSQL -Version 2.1.0-rc1
Install-Package Npgsql.EntityFrameworkCore.PostgreSQL.NetTopologySuite -Version 2.1.0-rc1
Once your packages are installed, in your DbContext class, override OnConfiguring to add the UseNetTopologySuite option:
protected override void OnConfiguring(DbContextOptionsBuilder builder)
{
builder.UseNpgsql("Host=localhost;Database=your_database;
Username=your_user;Password=your_password",
o => o.UseNetTopologySuite());
}
To make sure that the extension is supported by your database add the following to your DbContext:
protected override void OnModelCreating(ModelBuilder builder)
{
builder.HasPostgresExtension("postgis");
}
Now you should be able to use PostgreSql spatial types and translate some operations to SQL, (e.g. ST_Area, ST_Contains, ST_As_Text, etc.).
The whole list of supported operations and how to use them in your EF queries is available here: http://www.npgsql.org/efcore/mapping/nts.html#operation-translation
Unfortunately ST_Transform or ST_Project do not seem to be supported as of now, but there is a link in the Website above where you can contact the developers and request them to be added.
In the meantime, you can use GDAL to transform the projection of your coordinates.
Install the package:
Install-Package Gdal.Core -Version 1.0.0
This package provides a multi-platform wrapper for GDAL for .NET core so you need to install the libraries and they should be accessible by your program.
You can find binaries for Windows and Linux here: https://trac.osgeo.org/gdal/wiki/DownloadingGdalBinaries
If you are using Windows you can use the following installer: http://download.osgeo.org/osgeo4w/osgeo4w-setup-x86_64.exe
Just select "Express Desktop Install" and GDAL in the "Select Packages" window.
By default the needed libraries are installed in C:\OSGeo4W64\bin.
You need to add this folder to your system path and restart Visual Studio.
By the way, to convert the coordinates, from all the libraries in C:\OSGeo4W64\bin I think you only need proj.dll so may be you can include this in your project (make sure it is copied to the output of your project) and then it should work and you don't need to install GDAL.
Here is an example of how to use it for the coordinate systems provided in your question:
using System;
using NetTopologySuite.Geometries;
using OSGeo.OSR;
using OSGeo.OGR;
namespace YourNamespace
{
public class SomeLocation
{
public int Id { get; set; }
public string Name { get; set; }
public Point Location { get; } = new Point(40.1234, 1.4321) { SRID = 4326 };
public Point LocationUpsNorth { get { return Wgs84ToWgs84UpsNorth(Location); } }
private static NetTopologySuite.Geometries.Point Wgs84ToWgs84UpsNorth(Point location)
{
if (location.SRID != 4326)
throw new Exception("Unsupported coordinate system: " + location.SRID);
OSGeo.OSR.SpatialReference wgs84Src = new OSGeo.OSR.SpatialReference("");
wgs84Src.ImportFromProj4("+proj=longlat +datum=WGS84 +no_defs");
OSGeo.OSR.SpatialReference stereoNorthPoleDest = new OSGeo.OSR.SpatialReference("");
stereoNorthPoleDest.ImportFromProj4("+proj=stere +lat_0=90 +lat_ts=90 +lon_0=0 +k=0.994 +x_0=2000000 +y_0=2000000 +datum=WGS84 +units=m +no_defs");
OSGeo.OSR.CoordinateTransformation ct = new OSGeo.OSR.CoordinateTransformation(wgs84Src, stereoNorthPoleDest);
double[] point = new double[3];
point[0] = location.X;
point[1] = location.Y;
point[2] = location.Z;
ct.TransformPoint(point);
return new Point(point[0], point[1]);
}
}
}
Result
Input: POINT (40.1234 1.4321)
Output: POINT (9944217.1796359234 -7426244.9918885585)
References:
http://www.npgsql.org/efcore/mapping/nts.html
http://spatialreference.org/ref/epsg/32661/
https://github.com/NetTopologySuite/
https://github.com/NetTopologySuite/ProjNet4GeoAPI/blob/develop/ProjNet.Tests/CoordinateTransformTests.cs
https://gis.stackexchange.com/questions/61541/searching-for-c-code-to-convert-from-utm-to-wgs1984-and-back#61574

Use Google Calendar API in User Control : System.IO.FileNotFoundException

I fail when trying to use the Google API v3 in a user control.
Steps:
Create a new project in Visual Studio Express 2013 Update 4. Target framework: .NET 4.5 (tried 4.0 too)
Install NuGet package "Google.Apis.Calendar.v3 Client Library" and all and all dependencies
Add new User Control "MyControl"
In MyCalendar_Load add the following line: CalendarService service = new ServiceCalendar();
Add using Google.Apis.Calendar.v3;
So the code of my control looks like:
using System;
using System.Windows.Forms;
using Google.Apis.Calendar.v3;
namespace Google_Calendar_Test
{
public partial class MyCalendar : UserControl
{
public MyCalendar()
{
InitializeComponent();
}
private void MyCalendar_Load(object sender, EventArgs e)
{
CalendarService service = new CalendarService();
}
}
}
Then I compile my solution so I get my newly created MyControl. When I try to put the control on the form the following error message appears:
System.IO.FileNotFoundException / Could not load file or assembly Google.Apis,
In the form I can add the CalendarService and start it without any problems. I'm puzzled.
Update
The version in the error message (V 1.0.0.23042) doesn't match to the version NuGet installed (V 1.0.0.26011). But this doesn't make any sense to me.

Categories

Resources