Rebuilding deprecated sqlite functionality from MVVMCross to Community.Sqlite - sqlite

The following code no longer registers correctly with the IOC. I am currently trying to switch to the Community.Plugins.Sqlite library.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using Cirrious.MvvmCross.Community.Plugins.Sqlite;
using FlashCardApp.Core.Entities;
using FlashCardApp.Core.Managers.FlashCardApp.Core.Services;
using FlashCardApp.Core.ViewModels.Dictionary;
namespace FlashCardApp.Core.Managers
{
class EnglishManager : IEnglishManager
{
private readonly ISQLiteConnection _connection;
public EnglishManager(ISQLiteConnectionFactory factory)
{
_connection = factory.Create("Dictionary.sqlite");
// _connection.CreateTable<English>();
}
I get the following stack trace error
mvx:Warning: 2.06 Problem creating viewModel of type DictionaryViewModel - problem MvxException: Failed to resolve parameter for parameter factory of type ISQLiteConnectionFactory when creating FlashCardApp.Core.Managers.EnglishManager at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.GetIoCParameterValues(Type type, ConstructorInfo firstConstructor)
How does one go about registering an ISQLiteConnectionFactory in a constructor. Or is there a new method of using this factory under the community plugin?
Edit: I added the community.sqlite plugin to my app.store project and now the ISQLFactory seems to be registering and creating but I get the following error
A first chance exception of type 'System.EntryPointNotFoundException' occurred in Cirrious.MvvmCross.Community.Plugins.Sqlite.WindowsStore.DLL
'FlashCardApp.Store.exe' (Managed (v4.0.30319)): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\11.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.DLL'
and
Unable to find an entry point named 'sqlite3_win32_set_directory' in DLL 'sqlite3'.
Thanks in advance
JH

Related

MVVMCross documentation needs updating for latest release?

I'm very new to MVVMCross and I was following the TipCalc tutorial however it seems it was written for an older version MVVMCross. I'm stuck in the TipCalc Android Project section because the MvvmCross package doesnt have a class called MvxAndroidApplication.
using System;
using Android.App;
using Android.Runtime;
using MvvmCross.Platforms.Android.Core; // this namespace doesn't exist
using MvvmCross.Platforms.Android.Views;
using TipCalc.Core;
namespace TipCalc.Droid
{
[Application]
public class MainApplication : MvxAndroidApplication<MvxAndroidSetup<App>, App>
{
public MainApplication(IntPtr javaReference, JniHandleOwnership transfer)
: base(javaReference, transfer)
{
}
}
}
The issue was with the Android version in the Project settings. Details in this link https://github.com/MvvmCross/MvvmCross/pull/3958

How to reference ServiceBus in azure functions v2?

This is not working (anymore): getting this error
CS0006: Metadata file 'Microsoft.Azure.ServiceBus' run.csx(11,23) and CS0234: The type or namespace name 'ServiceBus' was not found
#r "Newtonsoft.Json"
#r "Microsoft.WindowsAzure.Storage"
#r "Microsoft.Azure.ServiceBus"
using System;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using System.Net;
using Microsoft.Azure.ServiceBus;
public static async Task Run(Message mySbMsg, ILogger log)
any idea?
thank you
#r "..\\bin\\Microsoft.Azure.ServiceBus.dll"
using System;
using System.Threading.Tasks;
using Microsoft.Azure.ServiceBus;
public static async Task Run(Message mySbMsg, ILogger log)
{
}
This assembly is not automatically added. take a look at following link for assemblies which are automatically added
https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-csharp#referencing-external-assemblies

Net Core 2: Cannot inherit from KeyNotFoundException

I have something weird:
I had a class like this:
using System;
using System.Collections.Generic;
namespace My.Client
{
public class XNotFoundException : KeyNotFoundException
{
public XFoundException(string s, Exception e) : base(s, e)
{
}
}
}
This class is published via nuget package which contains Refit 4.3.0 and AspNetCore.All 2.0.6.
A project which references this package tries to use the class.. but the build cannot find the class. Other classes from this package work just fine. The error they receive is:
CS0246: The type or namespace name 'XNotFoundException' could not be
found (are you missing a using directive or an assembly reference?)
If I inherit from Exception instead of KeyNotFoundException, it "works". But why? Is there some complication that I missed?

Unit Test Project: "No connection string could be found in the application config file"

I had an existing MVC5 web app. I just created a new Unit Test Project and added the following code....
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SomethingApp.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SUT = SomethingApp.Services.ReportingServices; // SUT = System Under Test
namespace SomethingApp.Services.Tests
{
[TestClass]
public class GettingScoreForQuestionShould
{
[TestMethod]
public void ReturnScoreWhenGivenValidData()
{
// Arrange
int eventId = 39;
int questionId = 271;
decimal score;
// Act
score = SUT.GetScoreForQuestion(eventId, questionId);
// Assert
Assert.AreEqual("80",score);
}
}
}
When the method GetScoreForQuestion runs in the normal web app it runs perfect. But, when I run it through the test method I'm getting this error...
Message: Test method SomethingApp.Services.Tests.GettingScoreForQuestionShould.ReturnScoreWhenGivenValidData
threw exception: System.InvalidOperationException: No connection string
named 'myDbContext' could be found in the application config file.
The error is, of course, coming from the method GetScoreForQuestion, which works fine in the normal web app.
I don't understand why I need to add an application config file and this config connection string to the test project. Seems like, since I'm calling the method in the MVC project, that this has the responsibility of making the connection and doing it's thing (which it's doing in the normal course of the app). Am I mistaking something?
And, I tried adding a new application.config file and the connection string to the unit test project, but then the test method won't show up anymore in the Test Explorer after build. Any suggestions? Thanks!
UPDATE ****
Here's the code for GetScoreForQuestion (the offending method, which works in the web app fine, but not when called thru the test method)....
public static decimal GetScoreForQuestion(int eventId, int ThingyQuestionId)
{
// the following line fails with the connection issue
var ThingyResults = Db.ThingyResults.Where(e => e.EventId == eventId && e.ThingyQuestionId == ThingyQuestionId)
.AsNoTracking().ToList();
:
:
:
}
Db is declared in the same class as...
public static class ReportingServices
{
private static readonly ThingyContext Db = new ThingyContext();
When you are executing a unittest, that project is your running application. So that is where the configuration file is read from. And note that you need an app.config, not a web.config.
It looks like you may be creating a new ThingyContext within your ReportingServices class. Look into injecting an Interface so that you can substitute a mock implementation for testing purposes.
Here's some links to help get you started:
https://romiller.com/2012/02/14/testing-with-a-fake-dbcontext/
https://ardalis.com/new-is-glue

xSocket WebRTC Sample error

Hi i have a problem i have a aplication that i m desenvolving an its the same princepel like facebook like a social engine in mvc 4 i am trying to put video-conference i already tried in a empty asp.net mvc4 empty internet application and it works xSocket.net WebRTC Sample so where is my error
so i followed the steps PM> Install-Package XSockets.Sample.WebRTC
1: Add a new XSockets.Web.Bootstrapper (ctrl+shift+a)
2: Under the "Web" tab go to the "Servers" section and set Use Visual Studio Development Server
using System.Web;
using XSockets.Core.Common.Socket;
[assembly: PreApplicationStartMethod(typeof(basicWebRTC.XSocketsWebBootstrapper1), "Start")]
namespace basicWebRTC
{
public static class XSocketsWebBootstrapper1
{
private static IXSocketServerContainer wss;
public static void Start()
{
wss = XSockets.Plugin.Framework.Composable.GetExport<IXSocketServerContainer>(); // when e start An exception of type 'XSockets.Plugin.Framework.Exceptions.ExportException' occurred in XSockets.Plugin.Framework.dll but was not handled in user code //
wss.StartServers();
}
}
}

Resources