MongoDB and Unity IL2CPP mobile builds

I am having the same problem, did you solve it?

I’m getting this issue now, as it looks like MongoDB doesn’t support it.

I’m having the same issue when building an UWP for HoloLens - seems to be a general problem with IL2CPP

Anyone find a workaround for this issue?

After a lot of tinkering I found a way to make the MongoDB C# Driver work with Unity IL2CPP builds (I tested it on PC and UWP builds, but I guess it works for others too)
For it to work I had to make a custom build of the driver, plus pay some attention to other details.
But before I go into a bit of detail of my findings, here’s a link to an example project that I uploaded: MongoDB IL2CPP Example Project (don’t forget to change the MongoDBTester.cs to use your instance of MongoDB)

So here’s what I did:

MongoDB Driver:
In ClientDocumentHelper.cs of the driver source is a function CreateOSDocument() which contains a section #if NET452 - I just removed that whole section and tried it out in Unity with the IL2CPP build and it solved the OPs NotSupportedException

Unity - Assembly Stripping:
The stripping process removed some code that is actually needed, which I fixed with a linker file - link.xml in the Plugins Folder of my example project.

Unity - AOT and Reflections:
The MongoDB Driver uses reflections for some things, like getting the right serializer for a collection. The AOT nature of C++ builds and the way IL2CPP works don’t mix well with that (see Unity Docs - Scripting Restrictions).
Fortunately this is easy enough to work around: If you use generic classes (like Dictionary) you need to specify the Serializer with the BsonSerializerAttribute
For constructors the same issue happens when using constructors with arguments - I just ensure that an zero argument public constructor is available for all classes that are used with MongoDB.

Unity - IPv4:
I’m not sure if this has anything to do with Unity or the MongoDB Driver, or maybe just the server why my instance of MongoDB was hosted, but I encountered a problem that my address protocol was not supported. So I wrote a workaround to use IPv4 instead.

Additional Note:
I noticed that auto-mapping of my classes did not always work. I haven’t quite figured out when and why it doesn’t work but if this happens just manually map the class with BsonClassMap.RegisterClassMap

Hope this helps, let me know if it works for you or if you encounter any other problems.

Hi Everyone,

I know I’m a little late to this thread, but I wanted to point out that MongoDB has a Realm SDK for Unity that is currently in Alpha. As far as I know it is scheduled to have a stable release later this year (2021).

You can learn more about it here:

https://www.mongodb.com/how-to/getting-started-realm-sdk-unity/

I’m hoping this takes some of the pain out of working with MongoDB and Unity.

I’m tagging @nirinchev who is the Engineer on the project.

Best,

Hey Stefan,

This works great in editor. When I try to make a build on Mac or iOS, the app just hangs with this error:

Test failed, exception: System.TimeoutException: A timeout occured after 30000ms selecting a server using CompositeServerSelector{ Selectors = MongoDB.Driver.MongoClient+AreSessionsSupportedServerSelector, LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000 } }. Client view of cluster state is { ClusterId : “1”, ConnectionMode : “Automatic”, Type : “Unknown”, State : “Disconnected”, Servers : [{ ServerId: “{ ClusterId : 1, EndPoint : “x.x.x.x:27017” }”, EndPoint: “x.x.x.x:27017”, ReasonChanged: “ServerInitialDescription”, State: “Disconnected”, ServerVersion: , TopologyVersion: , Type: “Unknown”, LastHeartbeatTimestamp: null, LastUpdateTimestamp: “2021-04-12T02:39:45.5177210Z” }] }.
at MongoDB.Driver.Core.Clusters.Cluster

Any ideas what’s causing that?

Is this the full stack trace? I also had timeout problems, but in my case the error also contained an HeartbeatException in the Servers list of the error message. So I doubt it is the same problem. In my case it was the problem with using IPv6, for which I wrote the GetIPv4Host function, are you using that?

You could also check Error Handling in the drivers reference.

You could try playing around with your connection string to see if you can find a solution with settings, depending on how your MongoDB is configured, like here.

I also found a post where it is mentioned that it can be related to firewall or security settings.

Please let me know if you find anything.

(Sorry for double-reply, I’m not allowed to post more than 2 links in one post because I’m new)

I tried Mac, Windows and iOS builds connecting to a mongodb server running on the local network, no issues whatsoever.

When I try the exact same server (I’ve tried windows and Mac) hosted on Linode or AWS or another network with port forwarding/security policies in place, the editor and Windows builds still work without issues, the Mac and iOS builds fail in the same way.

Also works just fine in Android. So if it’s a server (latest mongodb community edition) issue, it’s gotta be something only iOS/Mac are being finicky about. And that’s only when connecting over the internet vs connecting to local lan.

And here’s the lengthy stack trace:

Try uploading data: { "name" : "test", "someBool" : true, "number" : -1323691331, "list" : [{ "value" : 0.29091730713844299 }, { "value" : 0.75945866107940674 }], "dictionary" : { "test_0" : { "value" : 1984966749 } } }
UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
MongoDBTester:ShowMessage(String)
<TestMongoDB>d__22:MoveNext()
System.Runtime.CompilerServices.AsyncVoidMethodBuilder:Start(TStateMachine&)
MongoDBTester:TestMongoDB(String)
<Start>d__17:MoveNext()
System.Runtime.CompilerServices.AsyncVoidMethodBuilder:Start(TStateMachine&)
MongoDBTester:Start()
 
(Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 39)

Test failed, exception: System.TimeoutException: A timeout occured after 30000ms selecting a server using CompositeServerSelector{ Selectors = MongoDB.Driver.MongoClient+AreSessionsSupportedServerSelector, LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:01 } }. Client view of cluster state is { ClusterId : "1", ConnectionMode : "Automatic", Type : "Unknown", State : "Disconnected", Servers : [{ ServerId: "{ ClusterId : 1, EndPoint : "x.x.x.x:27017" }", EndPoint: "x.x.x.x:27017", ReasonChanged: "ServerInitialDescription", State: "Disconnected", ServerVersion: , TopologyVersion: , Type: "Unknown", LastHeartbeatTimestamp: null, LastUpdateTimestamp: "2021-04-14T01:55:57.1876190Z" }] }.
  at MongoDB.Driver.Core.Clusters.Cluster.ThrowTimeoutException (MongoDB.Driver.Core.Clusters.ServerSelectors.IServerSelector selector, MongoDB.Driver.Core.Clusters.ClusterDescription description) [0x00000] in <00000000000000000000000000000000>:0 
  at MongoDB.Driver.Core.Clusters.Cluster+WaitForDescriptionChangedHelper.HandleCompletedTask (System.Threading.Tasks.Task completedTask) [0x00000] in <00000000000000000000000000000000>:0 
  at MongoDB.Driver.Core.Clusters.Cluster+<WaitForDescriptionChangedAsync>d__57.MoveNext () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.InvokeMoveNext (System.Object stateMachine) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.ContextCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Action.Invoke () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction (System.Action action, System.Boolean allowInlining, System.Threading.Tasks.Task& currentTask) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.Task.FinishContinuations () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.Task.FinishStageThree () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.Task`1[TResult].TrySetResult (TResult result) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.TaskFactory+CompleteOnInvokePromise.Invoke (System.Threading.Tasks.Task completingTask) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.Task.FinishContinuations () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.Task.FinishStageThree () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.Task`1[TResult].TrySetResult (TResult result) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.Task+DelayPromise.Complete () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.Task+<>c.<Delay>b__276_1 (System.Object state) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.TimerCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Timer+Scheduler.TimerCB (System.Object o) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.WaitCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.ThreadPoolWorkQueue.Dispatch () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () [0x00000] in <00000000000000000000000000000000>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Runtime.CompilerServices.ConfiguredTaskAwaitable+ConfiguredTaskAwaiter.GetResult () [0x00000] in <00000000000000000000000000000000>:0 
  at MongoDB.Driver.Core.Clusters.Cluster+<SelectServerAsync>d__49.MoveNext () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.InvokeMoveNext (System.Object stateMachine) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.ContextCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Action.Invoke () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction (System.Action action, System.Boolean allowInlining, System.Threading.Tasks.Task& currentTask) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.Task.FinishContinuations () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.Task.FinishStageThree () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.Task.FinishStageTwo () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.Task.Finish (System.Boolean bUserDelegateExecuted) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.Task`1[TResult].TrySetException (System.Object exceptionObject) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[TResult].SetException (System.Exception exception) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.SetException (System.Exception exception) [0x00000] in <00000000000000000000000000000000>:0 
  at MongoDB.Driver.Core.Clusters.Cluster+<WaitForDescriptionChangedAsync>d__57.MoveNext () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.InvokeMoveNext (System.Object stateMachine) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.ContextCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Action.Invoke () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction (System.Action action, System.Boolean allowInlining, System.Threading.Tasks.Task& currentTask) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.Task.FinishContinuations () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.Task.FinishStageThree () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.Task`1[TResult].TrySetResult (TResult result) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.TaskFactory+CompleteOnInvokePromise.Invoke (System.Threading.Tasks.Task completingTask) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.Task.FinishContinuations () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.Task.FinishStageThree () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.Task`1[TResult].TrySetResult (TResult result) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.Task+DelayPromise.Complete () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.Task+<>c.<Delay>b__276_1 (System.Object state) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.TimerCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Timer+Scheduler.TimerCB (System.Object o) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.WaitCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.ThreadPoolWorkQueue.Dispatch () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () [0x00000] in <00000000000000000000000000000000>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in <00000000000000000000000000000000>:0 
  at MongoDB.Driver.MongoClient+<AreSessionsSupportedAfterSeverSelctionAsync>d__55.MoveNext () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.InvokeMoveNext (System.Object stateMachine) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.ContextCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Action.Invoke () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction (System.Action action, System.Boolean allowInlining, System.Threading.Tasks.Task& currentTask) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.Task.FinishContinuations () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.Task.FinishStageThree () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.Task.FinishStageTwo () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.Task.Finish (System.Boolean bUserDelegateExecuted) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.Task`1[TResult].TrySetException (System.Object exceptionObject) [0x00000] in <00000000000000000000000000000000>:0 

  at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[TResult].SetException (System.Exception exception) [0x00000] in <00000000000000000000000000000000>:0 
  at MongoDB.Driver.Core.Clusters.Cluster+<SelectServerAsync>d__49.MoveNext () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.InvokeMoveNext (System.Object stateMachine) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.ContextCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Action.Invoke () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction (System.Action action, System.Boolean allowInlining, System.Threading.Tasks.Task& currentTask) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.Task.FinishContinuations () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.Task.FinishStageThree () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.Task.FinishStageTwo () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.Task.Finish (System.Boolean bUserDelegateExecuted) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.Task`1[TResult].TrySetException (System.Object exceptionObject) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[TResult].SetException (System.Exception exception) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.SetException (System.Exception exception) [0x00000] in <00000000000000000000000000000000>:0 
  at MongoDB.Driver.Core.Clusters.Cluster+<WaitForDescriptionChangedAsync>d__57.MoveNext () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.InvokeMoveNext (System.Object stateMachine) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.ContextCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Action.Invoke () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction (System.Action action, System.Boolean allowInlining, System.Threading.Tasks.Task& currentTask) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.Task.FinishContinuations () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.Task.FinishStageThree () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.Task`1[TResult].TrySetResult (TResult result) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.TaskFactory+CompleteOnInvokePromise.Invoke (System.Threading.Tasks.Task completingTask) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.Task.FinishContinuations () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.Task.FinishStageThree () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.Task`1[TResult].TrySetResult (TResult result) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.Task+DelayPromise.Complete () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.Task+<>c.<Delay>b__276_1 (System.Object state) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.TimerCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Timer+Scheduler.TimerCB (System.Object o) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.WaitCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.ThreadPoolWorkQueue.Dispatch () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () [0x00000] in <00000000000000000000000000000000>:0 
--- End of stack trace from previous location where exception was thrown ---
....

To me this sounds a lot like its related to security policies on apple devices. Maybe you can find some information about that? Did you enable internet capabilities for your iOS/macOS builds? (I found this for example)

“Requires Persistent WiFi” and “Allow downloads over HTTP (nonsecure)” was already enabled for iOS build. Double checked that “NSAllowsArbitraryLoads” and “UIRequiresPersistentWiFi” are set in the info.plist.

Network connectivity isn’t the issue either. Tried pinging before connecting to the database and I get the same results on all platforms.

The fact that it connects to a LAN database but not a WAN one only on iOS/Mac certainly points to security policies but I can’t see which setting might be missing.

I stand corrected. The sample project was set to Mono as scripting backend for Android. When I set it to IL2CPP, I get the same failure on Android as I get on Mac and iOS when connecting to a WAN mongodb instance. Furthermore, it won’t connect to a LAN mongodb instance either.

I’m sorry to hear that. Unfortunately I have no idea where the problem could be.
For me the project worked with a remote (community) server, with PC and UWP builds.

I am having the same problem. Implemented the MongoDB fully within the editor but when I builded the project to iOS it didn’t work. it returned this error:

NotSupportedException: ./External/il2cpp/builds/libil2cpp/icalls/mscorlib/System.Reflection/Module.cpp(112) : Unsupported internal call for IL2CPP:Module::GetPEKind - “This icall is not supported by il2cpp.”

I had the same error and made a custom build of the driver. You can find it here

For more explaination what I did to make it work check my previous reply to this topic.

Stefan,

How did you determine what code gets stripped by the stripping process? Maybe I need to force more code to be included in link.xml?

If the problem is assembly stripping then it should throw an exception. I don’t remember the exact error, but IIRC it should mention the function that wasn’t found plus a stack trace