How to use System.Data.SQLite under mono? - sqlite

I downloaded System.Data.SQLite, and tried to compile the following sample code.
using System;
using System.Data;
using System.Data.Common;
using System.Data.SQLite;
namespace test
{
class Program
{
static void Main(string[] args)
{
SQLiteConnection.CreateFile("/Users/smcho/Desktop/SQLite-1/example/mydatabasefile.db3");
}
}
}
I ran the following command
mcs db.cs -r:System.Data.dll -r:System.Data.SQLite.dll
But, I got the error messages as follows.
** (/opt/local/lib/mono/1.0/mcs.exe:43249): WARNING **: The class System.Data.Common.DbConnection could not be loaded, used in System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
db.cs(12,7): error CS0103: The name `SQLiteConnection' does not exist in the current context
Compilation failed: 1 error(s), 0 warnings
What might be wrong?

Using the gmcs instead of mcs solved this issue.
gmcs db.cs -r:System.Data.dll,System.Data.SQLite.dll

Related

Error in uno platform auto generated file and program.cs - only on Mac

I have a simple app based un uno platform. On Windows I can build and run it without any problem. But on VS for Mac the compiler gives error to the auto generated RemoteControl.g.cs file:
Error CS0826: No best type found for implicitly-typed array (CS0826)
(UnoTeszt.Wasm)
Error CS1503: Argument 2: cannot convert from '?[]'
to 'string[]' (CS1503) (UnoTeszt.Wasm)
// <auto-generated>
// ***************************************************************************************
// This file has been generated by the package Uno.UI.RemoteControl - for Xaml Hot Reload.
// Documentation: https://platform.uno/docs/articles/features/working-with-xaml-hot-reload.html
// ***************************************************************************************
// </auto-generated>
// <autogenerated />
#pragma warning disable // Ignore code analysis warnings
[assembly: global::Uno.UI.RemoteControl.ServerEndpointAttribute("fe80::1%1", 0)]
[assembly: global::Uno.UI.RemoteControl.ServerEndpointAttribute("fe80::109d:3e33:34e7:51fb%4", 0)]
[assembly: global::Uno.UI.RemoteControl.ServerEndpointAttribute("10.111.111.61", 0)]
[assembly: global::Uno.UI.RemoteControl.ServerEndpointAttribute("fe80::5805:f7ff:feaa:6ec3%8", 0)]
[assembly: global::Uno.UI.RemoteControl.ServerEndpointAttribute("fe80::5805:f7ff:feaa:6ec3%9", 0)]
[assembly: global::Uno.UI.RemoteControl.ServerEndpointAttribute("fe80::1d3:92b1:ff7d:cf5%10", 0)]
[assembly: global::Uno.UI.RemoteControl.ServerEndpointAttribute("fe80::77d1:f7a1:4393:622b%11", 0)]
[assembly: global::Uno.UI.RemoteControl.ProjectConfigurationAttribute(
#"/Users/kistelekig/Documents/Vitarex/FilmesApp/UnoTeszt/UnoTeszt/UnoTeszt.Wasm/UnoTeszt.Wasm.csproj",
new[]{}
)]
And I have an other problem as well in the Program.cs:
[...]/UnoTeszt/UnoTeszt.Wasm/Program.cs(20,20): Error CS0246: The type or namespace name 'App' could not be found (are you missing a using directive or an assembly reference?) (CS0246) (UnoTeszt.Wasm)
using System;
using Windows.UI.Xaml;
namespace UnoTeszt.Wasm
{
public class Program
{
private static App _app;
static int Main(string[] args)
{
Windows.UI.Xaml.Application.Start(_ => _app = new App());
return 0;
}
}
}
I have the latest version of VS for Mac and MacOS installed.
This usually happens when there's no XAML files tagged as <Page /> in your project. Make sure to correctly reference your shared project.
I have found the root issue. When I create a project via dotnet new:
dotnet new -i Uno.ProjectTemplates.Dotnet
dotnet new unoapp -o App-CrossPlatform
I have the next shared project
App-CrossPlatform\App-CrossPlatform.Shared\App-CrossPlatform.Shared.shproj
App-CrossPlatform\App-CrossPlatform.Shared\App-CrossPlatform.Shared.projitems
But in other (android, ios) projects there are the next imports:
<Import Project="..\App_CrossPlatform.Shared\App_CrossPlatform.Shared.projitems" Label="Shared" Condition="Exists('..\App_CrossPlatform.Shared\App_CrossPlatform.Shared.projitems')" />
Yes... Symbol - vs _...
I have created an issue:
https://github.com/unoplatform/uno/issues/4217

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?

Rebuilding deprecated sqlite functionality from MVVMCross to Community.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

Get Assembly version on windows phone 7

In my c# applications I usually get the version (to show the customer) using the following code:
System.Reflection.Assembly.GetExecutingAssembly().GetName().Version
This does not work in Windows Phone 7 (it hangs the emulator, and phone crashing is a no-no for MS).
So, how do I get the version of the executing on a windows phone 7 device??
[Update] as noted in the comments below, calling GetName() in a wp7 app seems to be the problem.
Try this:
private static string GetVersionNumber()
{
var asm = Assembly.GetExecutingAssembly();
var parts = asm.FullName.Split(',');
return parts[1].Split('=')[1];
}
Does parsing it out of
Assembly.GetExecutingAssembly().FullName
work for you?
example output: SomeApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
edit: don't need to go through ManifestModule
First, I think it's more apt to use the assembly's file version info for conveying the application version to the user. See http://techblog.ranjanbanerji.com/post/2008/06/26/Net-Assembly-Vs-File-Versions.aspx
Second, what about doing this:
using System;
using System.Linq;
using System.Reflection;
public static class AssemblyExtensions
{
public static Version GetFileVersion(this Assembly assembly)
{
var versionString = assembly.GetCustomAttributes(false)
.OfType<AssemblyFileVersionAttribute>()
.First()
.Version;
return Version.Parse(versionString);
}
}
public static string GetVersion()
{
return Regex.Match(Assembly.GetExecutingAssembly().FullName, #"Version=(?<version>[\d\.]*)").Groups["version"].Value;
}
is fairly clean as well.

Resources