I get this error:
"Could not load file or assembly 'System.IO.FileSystem, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)"
Project: windows 10 UWP
Version: LiteDB 3.1.0
Code sample:
using (var db = new LiteDatabase(@"KeyValues.db"))
{
// Get customer collection
var keyValues = db.GetCollection
///on the next line below the exception is thrown
var keyV = keyValues?.FindOne(kv => kv.Key.Equals(keyValue.Key, StringComparison.OrdinalIgnoreCase));
if (keyV == null)
{
//insert
keyValues.Insert(keyValue);
}
else
{
//update
keyValues.Update(keyValue);
}
keyValues.EnsureIndex(k => k.Key);
return true;
}
What does your project.json look like? I just quickly done a sample app with VS 2017 with LiteDB 3.10 and it works alright. Please provide more details.
Hi @xied75, can you post this tips to works in UWP? I can edit Wiki page about portable version
@mbdavid I didn't do anything special at all, just create a blank UWP app and nuget LiteDB v3.1 and that's it, I even copied your example as is and everything works fine.
e.g. This is the project.json
{
"dependencies": {
"Microsoft.NETCore.UniversalWindowsPlatform": "5.2.2",
"LiteDB": "3.1.0"
},
"frameworks": {
"uap10.0": {}
},
"runtimes": {
"win10-arm": {},
"win10-arm-aot": {},
"win10-x86": {},
"win10-x86-aot": {},
"win10-x64": {},
"win10-x64-aot": {}
}
}
And this is the MainPage.xaml.cs
using System.IO;
using LiteDB;
using Windows.Storage;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace App1
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
static string ConnectionString = Path.Combine(ApplicationData.Current.LocalFolder.Path, "MyData.db");
public MainPage()
{
InitializeComponent();
Loaded += MainPage_Loaded;
}
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
// Open database (or create if doesn't exist)
using (var db = new LiteDatabase(ConnectionString))
{
// Get customer collection
var col = db.GetCollection<Customer>("customers");
// Create your new customer instance
var customer = new Customer
{
Name = "John Doe",
Phones = new string[] { "8000-0000", "9000-0000" },
Age = 39,
IsActive = true
};
// Create unique index in Name field
col.EnsureIndex(x => x.Name, true);
// Insert new customer document (Id will be auto-incremented)
col.Insert(customer);
// Update a document inside a collection
customer.Name = "Joana Doe";
col.Update(customer);
// Use LINQ to query documents (will create index in Age field)
var results = col.Find(x => x.Age > 20);
}
}
}
}
It seems this lib requires "Microsoft.NETCore.UniversalWindowsPlatform": "5.2.2". Just update the NETCore via nuget and you'll see the magic
@Harmen70 I'm closing this as it seems like your issue has been resolved. Feel free to re-open it, if you feel like this is still the case on newer versions.
Most helpful comment
@mbdavid I didn't do anything special at all, just create a blank UWP app and nuget LiteDB v3.1 and that's it, I even copied your example as is and everything works fine.
e.g. This is the project.json
And this is the MainPage.xaml.cs