I'm working on a mobile app with Xamarin Forms and intend to use a Mongo database.
I'm using Visual Studio 2019 with the MongoDB Driver Version 2.9.2 and android 28 as target SDK version.
I created a cluster on MongoDB Atlas, whitelisted all IP addresses for now, and tried to connect the app to the cluster with the connection string I was provided for the cluster(in the code below I replaced the real username and password with placeholders).
Here's the code:
private const string CONNECTION_STRING = "mongodb+srv://username:password#cluster0-uswax.mongodb.net/test?retryWrites=true&w=majority";
var client = new MongoClient(CONNECTION_STRING);
If I run the program with the Android emulator, the line where the MongoClient is created is where the program crashes with the following exception:
System.AggregateException
Message=Error resolving name servers (Value cannot be null.
Parameter name: source) (Could not find file "/etc/resolv.conf")
Source=DnsClient
StackTrace:
at DnsClient.NameServer.ResolveNameServers (System.Boolean skipIPv6SiteLocal, System.Boolean fallbackToGooglePublicDns) [0x0005e] in <93b57b4b99c64a96a2c065ea9ae1fc1f>:0
at DnsClient.LookupClient..ctor () [0x00000] in <93b57b4b99c64a96a2c065ea9ae1fc1f>:0
at MongoDB.Driver.Core.Configuration.ConnectionString.Resolve (System.Boolean resolveHosts) [0x00011] in <bfbe70fcd6734952960e694cb03fd3c6>:0
at MongoDB.Driver.MongoUrl.Resolve (System.Boolean resolveHosts) [0x00015] in <f2c302ca191a4adf889da299a582e348>:0
at MongoDB.Driver.MongoClientSettings.FromUrl (MongoDB.Driver.MongoUrl url) [0x0001b] in <f2c302ca191a4adf889da299a582e348>:0
at MongoDB.Driver.MongoClientSettings.FromConnectionString (System.String connectionString) [0x00006] in <f2c302ca191a4adf889da299a582e348>:0
at MongoDB.Driver.MongoClient..ctor (System.String connectionString) [0x00000] in <f2c302ca191a4adf889da299a582e348>:0
at Socializer.Helpers.MongoCrud..ctor (System.String connectionString, System.String databaseName) [0x00008] in D:\Data\projects\xamarin\Socializer\Socializer\Socializer\Helpers\MongoCrud.cs:18
at Socializer.App..ctor () [0x0001b] in D:\Data\projects\xamarin\Socializer\Socializer\Socializer\App.xaml.cs:27
at Socializer.Droid.MainActivity.OnCreate (Android.OS.Bundle savedInstanceState) [0x0002f] in D:\Data\projects\xamarin\Socializer\Socializer\Socializer.Android\MainActivity.cs:24
at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_savedInstanceState) [0x00011] in <11a340ccc8de43f09c97400139266ef5>:0
at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.8(intptr,intptr,intptr)
When I was looking for a solution to this problem I found this bug report,
stating that "Android is not currently a supported platform for the .NET driver"
Does that mean I cannot use MongoDB for Android applications or is there any other way? Thanks!
Edit: I also found this possible solution. The user that provided the answer states that "from Android 8 (Oreo), access to net.dns has been removed". Indeed when I remove android:targetSdkVersion="28" from my AndroidManifest.xml, the program no longer crashes, but that won't be an option once I want to upload the app to the play store.
The solution above is based on a custom implementation to get DNS servers but I do not know how I would implement this function into my code. I would appreciate it a lot if anyone could help me with that.
Here is the function:
public List<IPEndPoint> GetDnsServers()
{
var context = Android.App.Application.Context;
List<IPEndPoint> endPoints = new List<IPEndPoint>();
ConnectivityManager connectivityManager =
(ConnectivityManager)context.GetSystemService(MainActivity.ConnectivityService);
Network activeConnection = connectivityManager.ActiveNetwork;
var linkProperties = connectivityManager.GetLinkProperties(activeConnection);
foreach (InetAddress currentAddress in linkProperties.DnsServers)
{
IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse(currentAddress.HostAddress), 53);
endPoints.Add(endPoint);
}
return endPoints;
}
I got this issue too. It turns out that, MongoDB Driver on Xamarin Android doesn't support DNS Seedlist Connection Format (starts from "mongodb+srv://") very well. So you have to use Standard Connection String Format (starts from "mongodb://").
Please go to Atlas and find your Standard Connection String by selecting an old version driver like C#/.NET 2.4
For more discription of these two connection ways, refer to this
Related
Researched this issue many times but didn't found solution of it. Working with xamarin forms version 5.0.0.2012, on win 10 os (saw many solutions for mac or linux but didn't found any for windows), using PCSC library version 5.0.0. Trying to invoke context.Establish method while debugging on Android 8.0:
public SimpleReader(ISCardContext context, bool releaseContextOnDispose = false)
{
if (context == null)
{
context = (ISCardContext) new SCardContext();
context.Establish(SCardScope.System);
releaseContextOnDispose = true;
}
this._context = context;
this._reader = (ISCardReader) new SCardReader(context);
this._releaseContextOnDispose = releaseContextOnDispose;
this._disconnectReaderOnDispose = true;
}
When, exception occur with message below:
System.DllNotFoundException: libpcsclite.so.1 assembly:<unknown assembly> type:<unknown type> member:(null)
at (wrapper managed-to-native) PCSC.Interop.Linux.LinuxNativeMethods.SCardEstablishContext(intptr,intptr,intptr,intptr&)
at PCSC.Interop.Linux.PCSCliteLinux.EstablishContext (PCSC.SCardScope dwScope, System.IntPtr pvReserved1, System.IntPtr pvReserved2, System.IntPtr& phContext) [0x00006] in C:\Users\danm\src\pcsc-sharp\src\PCSC\Interop\Linux\PCSCliteLinux.cs:39
at PCSC.SCardContext.Establish (PCSC.SCardScope scope) [0x00020] in C:\Users\danm\src\pcsc-sharp\src\PCSC\SCardContext.cs:81
at App1xx.Services.SimpleReader.SimpleReader..ctor (PCSC.ISCardContext context, System.Boolean releaseContextOnDispose) [0x00023] in C:\Users\vzhynkin\source\repos\App1xx\App1xx\App1xx\Services\SimpleReaderLib\SimpleReader.cs:59
at App1xx.Services.SimpleReader.SimpleReader..ctor () [0x00000] in C:\Users\vzhynkin\source\repos\App1xx\App1xx\App1xx\Services\SimpleReaderLib\SimpleReader.cs:70
at App1xx.Services.UaIdRLib.IdCardReader.connect () [0x00002] in C:\Users\vzhynkin\source\repos\App1xx\App1xx\App1xx\Services\UaIdRLib\IdCardReader.cs:371
at App1xx.Views.AboutPage.OnButtonClicked (System.Object sender, System.EventArgs args) [0x0000f] in C:\Users\vzhynkin\source\repos\App1xx\App1xx\App1xx\Views\AboutPage.xaml.cs:22
at Xamarin.Forms.Button.Xamarin.Forms.Internals.IButtonElement.PropagateUpClicked () [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Button.cs:187
at Xamarin.Forms.ButtonElement.ElementClicked (Xamarin.Forms.VisualElement visualElement, Xamarin.Forms.Internals.IButtonElement ButtonElementManager) [0x0001f] in D:\a\1\s\Xamarin.Forms.Core\ButtonElement.cs:61
at Xamarin.Forms.Button.SendClicked () [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Button.cs:173
at Xamarin.Forms.Platform.Android.ButtonElementManager.OnClick (Xamarin.Forms.VisualElement element, Xamarin.Forms.IButtonController buttonController, Android.Views.View v) [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.Android\ButtonElementManager.cs:25
at Xamarin.Forms.Platform.Android.FastRenderers.ButtonRenderer.Android.Views.View.IOnClickListener.OnClick (Android.Views.View v) [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.Android\FastRenderers\ButtonRenderer.cs:72
at Android.Views.View+IOnClickListenerInvoker.n_OnClick_Landroid_view_View_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_v) [0x00010] in /Users/builder/azdo/_work/278/s/xamarin-android/src/Mono.Android/obj/Release/monoandroid10/android-30/mcw/Android.Views.View.cs:2252
at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.68(intptr,intptr,intptr)
Does anyone faced with this issue?
The PCSC library does not appear to explicitly support Android. In my experience, nugets that work with Xamarin.Android have explicit dependencies set for the platform, but this one does not.
The library tries to use P/Invoke wrappers around native code. You can see that there are implementations for a number of operating systems here, but I don't see any references to Android. The stack trace shows that the code is deciding to use the Linux wrapper, which makes sense. It's looking for the libpcsclite.so.1 native "C/C++" library, but it's not finding it. That library has a home page that does not reference Android.
The PCSC nuget docs state:
pcsc-sharp does not contain any device drivers. A PC/SC compliant
reader + driver is mandatory.
That's the libpcsclite.so.1 . Either your Android device doesn't provide it, or if it does, it's not in a location that your Android app can find it. My Android device (running Android 9) does not have that library in any of /system/*lib* directories, which means that at least for my device someone would need to compile that native library for the CPU (usually arm64) for the device. If you can either compile the native code yourself or find someone who has, AND the native code supports the reader on your Android device, then you could get the whole thing to work.
I don't have any experience with PCSC myself - just some experience with Xamarin and native libraries.
I've been trying to run a server on my pi3 that uses mysql (mariadb) and connects like this:
mySQLSettings.connection = new MySqlConnection("SERVER=localhost;DATABASE=servertest;UID=root;PASSWORD=;");
mySQLSettings.connection.Open();
It works perfectly fine on Windows when i use XAMPP. However when i run the app on my pi it throws me this:
Could not connect to MySQL: MySql.Data.MySqlClient.MySqlException (0x80004005): Client does not support authentication protocol requested by server; consider upgrading MariaDB client
at MySql.Data.MySqlClient.MySqlStream.ReadPacket () [0x0006e] in <61bbf0b98df94765b3636dc3aa92c9d7>:0
at MySql.Data.MySqlClient.NativeDriver.AuthenticateNew (System.Boolean reset) [0x000ed] in <61bbf0b98df94765b3636dc3aa92c9d7>:0
at MySql.Data.MySqlClient.NativeDriver.Authenticate (System.Boolean reset) [0x00040] in <61bbf0b98df94765b3636dc3aa92c9d7>:0
at MySql.Data.MySqlClient.NativeDriver.Open () [0x00344] in <61bbf0b98df94765b3636dc3aa92c9d7>:0
at MySql.Data.MySqlClient.Driver.Open () [0x0000c] in <61bbf0b98df94765b3636dc3aa92c9d7>:0
at MySql.Data.MySqlClient.Driver.Create (MySql.Data.MySqlClient.MySqlConnectionStringBuilder settings) [0x00058] in <61bbf0b98df94765b3636dc3aa92c9d7>:0
at MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection () [0x0001e] in <61bbf0b98df94765b3636dc3aa92c9d7>:0
at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection () [0x000b5] in <61bbf0b98df94765b3636dc3aa92c9d7>:0
at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver () [0x00051] in <61bbf0b98df94765b3636dc3aa92c9d7>:0
at MySql.Data.MySqlClient.MySqlPool.GetConnection () [0x00021] in <61bbf0b98df94765b3636dc3aa92c9d7>:0
at MySql.Data.MySqlClient.MySqlConnection.Open () [0x0013e] in <61bbf0b98df94765b3636dc3aa92c9d7>:0
at GameServer.MySQL.ConnectToMySQLServer () [0x00000] in <16fb46a8a2244c9e90373e583102cae7>:0
The version of MariaDB is 10.3.22 and I'm using the MySql.Data-6.4 dll
Am I missing something simple?
Thanks in advance!
You're using a pretty old version of MySql.Data.dll, which may not support the authentication scheme your server is using.
In this case, I'd recommend switching to MySqlConnector, which has better client support for MariaDB, including its auth_gss_client and auth_ed25519 authentication schemes (the latter in a separate package).
i followed the unity "tanks!" tutorial and now i'm trying to port the game on Android, it's my first time on Unity, now when it's going to build the APK unity tells me "Failed To Build APK" and then i get some errors, i'm attaching you the error i think it's fatal, please tell me what's wrong with it.
CommandInvokationFailure: Failed to build apk.
C:/Program Files/Java/jdk-9.0.1\bin\java.exe -Xmx2048M -D com.android.sdkmanager.toolsdir="C:/Android_SDK\tools" -D file.encoding=UTF8 -jar "C:\Program Files\Unity\Editor\Data\PlaybackEngines\AndroidPlayer/Tools\sdktools.jar"-
stderr[
Exception in thread "main" java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at SDKMain.main(SDKMain.java:130)
Caused by: java.lang.NoClassDefFoundError: sun/misc/BASE64Encoder
at com.android.sdklib.internal.build.SignedJarBuilder.<init>(SignedJarBuilder.java:177)
at com.android.sdklib.build.ApkBuilder.init(ApkBuilder.java:446)
at com.android.sdklib.build.ApkBuilder.<init>(ApkBuilder.java:422)
at com.android.sdklib.build.ApkBuilder.<init>(ApkBuilder.java:362)
at UnityApkBuilder.<init>(UnityApkBuilder.java:214)
at UnityApkBuilder.main(UnityApkBuilder.java:34)
... 5 more
Caused by: java.lang.ClassNotFoundException: sun.misc.BASE64Encoder
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:466)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:563)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
... 11 more
]
stdout[
]
exit code: 1
UnityEditor.Android.Command.WaitForProgramToRun (UnityEditor.Utils.Program p, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)
UnityEditor.Android.Command.Run(System.Diagnostics.ProcessStartInfo psi, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)
UnityEditor.Android.AndroidSDKTools.RunCommandInternal (System.String javaExe, System.String sdkToolsDir, System.String[] sdkToolCommand, Int32 emoryMB, System.String workingdir, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)
UnityEditor.Android.AndroidSDKTools.RunCommandSafe (System.String javaExe, System.String sdkToolsDir, System.String[] sdkToolCommand, Int32 emoryMB, System.String workingdir, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)
If you execute jdeps on your application, you would be able to see that sun.misc.BASE64Encoder has been deprecated and can be replaced with java.util.Base64 which is there since JDK 1.8.
The migration guide reads this as well :
A few sun.* APIs have been removed in JDK 9. Notably,
sun.misc.BASE64Encoder and sun.misc.BASE64Decoder have been removed.
Instead, use the supported java.util.Base64 class, which was added in
Java SE 8.
In your case, since you rely on third parties(android sdktools) which themselves haven't resolved this. I'm afraid you might have to stick with 1.8 and in the meanwhile, this can be reported to their trackers once they plan to migrate their artifacts.
Of course, this also means you would have to at some point in time upgrade to using their Java 9 compatible version of the jar if and when they plan to release.
Update : This can be tracked on Unity#956425 for further updates.
I’m trying to add SQL Server support to the Mono (on Linux, not Android if it matters) version of one of our products.
I have a codebase that works fine on Windows, but under Mono, it’s not behaving. We’re using SQL Authentication, not NT.
I am able to get back a list of table names, so I know it’s “talking” to the database, but when I attempt to query rows from a table I get this:
[ERROR] FATAL UNHANDLED EXCEPTION: System.Exception: Unknown packet type 129
at Mono.Data.Tds.Protocol.TdsComm.GetPhysicalPacketHeader () [0x00000] in :0
at Mono.Data.Tds.Protocol.TdsComm.GetPhysicalPacket () [0x00000] in :0
at Mono.Data.Tds.Protocol.TdsComm.Peek () [0x00000] in :0
at Mono.Data.Tds.Protocol.Tds.NextResult () [0x00000] in :0
at System.Data.SqlClient.SqlCommand.ExecuteScalar () [0x00000] in :0
at OpenNETCF.ORM.SQLStoreBase`1[OpenNETCF.ORM.SqlEntityInfo].ExecuteScalar (System.String sql) [0x00000] in :0
at OpenNETCF.ORM.SqlServerDataStore.get_ServerVersion () [0x00000] in :0
at OpenNETCF.ORM.SqlServerDataStore.Fetch (System.String entityName, Int32 fetchCount, Int32 firstRowOffset, System.String sortField, FieldSearchOrder sortOrder, OpenNETCF.ORM.FilterCondition filter, Boolean fillReferences) [0x00000] in :0
at SolutionFamily.Storage.DataEntityProvider.GetEntityInstances (System.String entityName, Int32 skipNumber, Int32 retrieveNumber) [0x00000] in :0
{more call stack omitted}
So it looks like the TDS version in Mono is old, maybe? Packet type 129 looks like it’s a “result” packet from version 7.0 on, so it's not something new as far as I can tell. It’s been in use since SQL Server 7, which itself is pretty far from “recent”.
So my questions, I guess, are:
Is connecting to a SQL Server 2012 database from a Mono app a supported scenario?
Has anyone had any luck connecting to a “modern” version of SQL Server?
Is there a newer version of TDS on the System.Data.* stuff available that adds support?
Any thoughts on how to proceed (other than debugging Mono and attempting to implement this stuff myself)?
I'm not sure if I'm looking at the right page here but have you consulted this?
Regardless of the DTS problem. Even if you manage to fix that, if SQL Server 2012 is really not supported I think you would have many more problems along the way.
It seems that the offending SQL statement in my code is this:
SELECT SERVERPROPERTY('productversion')
I tried chaning the call from an ExecuteScalar() to an ExecuteReader() and then reading the first column of the first row, but that, too, explodes. There's something about that statement (or more likely what SQL Server is returning as a result from it) that TDS doesn't like.
Fortunately we only use the resulting version for determining what types of queries to run (we have faster queries for newer servers that support them) and just reverting to "old" still appears to allow all the rest of the code to run, so I modified the caller to look like this:
public Version ServerVersion
{
get
{
// Mono doesn't like selecting SERVERPROPERTY, at least not from SQL 2012
if (Environment.OSVersion.Platform == PlatformID.Unix)
{
return new Version(1, 0);
}
if (m_version == null)
{
var v = this.ExecuteScalar("SELECT SERVERPROPERTY('productversion')");
m_version = new Version(v.ToString());
}
return m_version;
}
}
Obviously the version number here isn't specifically correct, but it works for my ORM, which then selects the "older" query styles and everything proceeds as usual. It still needs more testing for any other failures, but so far creating tables and inserting data on a SQL Server 2012 machine using the Mono.SqlClient seems to work fine.
have been working on a project intended for iOS deployment. Until recently, we have been building and deploying to our client via webplayer. However, I am now attempting to shift to releasing builds on iOS . But, no matter what I try, when I go to compile the project I receive the following error messages:
Cross compilation job Mono.WebBrowser.dll failed.
UnityEngine.UnityException: Failed AOT cross compiler: /Applications/Unity_45/Unity.app/Contents/PlaybackEngines/iOSSupport/Tools/OSX/mono-xcompiler --aot=full,asmonly,nodebug,static,outfile="Mono.WebBrowser.dll.s" "Mono.WebBrowser.dll" current dir : /Users/admin/Desktop/UI_gg_current/Temp/StagingArea/Data/Managed
Env: Apple_PubSub_Socket_Render = '/tmp/launch-7SV8Ex/Render'
LOGNAME = 'admin'
PATH = '/usr/bin:/bin:/usr/sbin:/sbin'
TMPDIR = '/var/folders/7c/s32nkpmx0yvgw4mmw_5vhxx40000gn/T/'
MONO_PATH = '/Users/admin/Desktop/UI_gg_current/Temp/StagingArea/Data/Managed'
SSH_AUTH_SOCK = '/tmp/launch-wpdtRI/Listeners'
USER = 'admin'
GC_DONT_GC = 'yes please'
Apple_Ubiquity_Message = '/tmp/launch-cfnoHv/Apple_Ubiquity_Message'
SHELL = '/bin/bash'
__CF_USER_TEXT_ENCODING = '0x1F5:0:0'
GAC_PATH = '/Users/admin/Desktop/UI_gg_current/Temp/StagingArea/Data/Managed'
HOME = '/Users/admin'
COMMAND_MODE = 'unix2003'
result file exists: False. Timed out: False
stdout:
stderr:
at UnityEditor.MonoProcessUtility.RunMonoProcess (System.Diagnostics.Process process, System.String name, System.String resultingFile) [0x00000] in <filename unknown>:0
at UnityEditor.MonoCrossCompile.CrossCompileAOT (BuildTarget target, System.String crossCompilerAbsolutePath, System.String assembliesAbsoluteDirectory, CrossCompileOptions crossCompileOptions, System.String input, System.String output, System.String additionalOptions) [0x00000] in <filename unknown>:0
at UnityEditor.MonoCrossCompile+JobCompileAOT.ThreadPoolCallback (System.Object threadContext) [0x00000] in <filename unknown>:0
UnityEditor.HostView:OnGUI()
and
Error building Player: UnityException: Cross compilation failed.
I am using Unity 4.5. To date I have : deleted third party dlls (including xml.linq.dll) , removed any instance of Lambda search operators (=>), and deleted the temp folder because I have seen these approaches used in similar situations (I know some aspects of Linq are not supported in iOS cross compile).
I have looked at similar issues such as this one: http://answers.unity3d.com/questions/439367/cross-compilation-failed-csharpdll.html. But, I am so perplexed, because it isn't the CSharp assembly causing my problem (which means it isn't one of my scripts?) I am not sure why it would even be including a WebBrowser.dll for an iOS build. Any help is greatly appreciated, as I feel I have searched far and wide for a resolution with no luck.
See the resolution that for this question here.