I want to execute a console program (.NET application) in a Docker container. It contains a mongo client and functions OK when used as a stand-alone program, however I keep receiving timeout errors when I try to make a docker container. I even verified that the connection from the Docker container functions by using the exact same connection string for MongoDB. There is a problem with the program that was made for Docker (I use AOT, but it should not be an issue because it works the same way for standalone).
Even stranger is the fact that it also functions properly when debugging in Visual Studio with Docker settings.
What am I doing incorrectly? NB: When I started the project, I used the dockerfile that Visual Studio made, and it also uses this file for debugging.
Error:
2024-12-28 19:35:37 A timeout occurred after 30000ms selecting a server using CompositeServerSelector{ Selectors = ReadPreferenceServerSelector{ ReadPreference = { Mode : Primary } }, LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000 }, OperationsCountServerSelector }. Client view of cluster state is { ClusterId : "1", Type : "Unknown", State : "Disconnected", Servers : [{ ServerId: "{ ClusterId : 1, EndPoint : "192.168.0.11:27017" }", EndPoint: "192.168.0.11:27017", ReasonChanged: "Heartbeat", State: "Disconnected", ServerVersion: , TopologyVersion: , Type: "Unknown", HeartbeatException: "MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server.
2024-12-28 19:35:37 ---> System.MissingMethodException: No suitable constructor found for serializer type: 'MongoDB.Bson.Serialization.Serializers.ExpandoObjectSerializer'.
2024-12-28 19:35:37 at MongoDB.Bson.Serialization.BsonSerializationProviderBase.CreateSerializer(Type, IBsonSerializerRegistry) + 0x22b
2024-12-28 19:35:37 at MongoDB.Bson.Serialization.CollectionsSerializationProvider.GetSerializer(Type, IBsonSerializerRegistry) + 0xa4
2024-12-28 19:35:37 at MongoDB.Bson.Serialization.BsonSerializerRegistry.CreateSerializer(Type type) + 0x9a
2024-12-28 19:35:37 at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey, Func`2) + 0xa0
2024-12-28 19:35:37 at MongoDB.Bson.Serialization.BsonSerializer.LookupSerializer[T]() + 0x51
2024-12-28 19:35:37 at MongoDB.Bson.BsonDefaults.get_DynamicDocumentSerializer() + 0x28
2024-12-28 19:35:37 at MongoDB.Bson.Serialization.BsonDeserializationContext.Builder..ctor(BsonDeserializationContext, IBsonReader) + 0x3b
2024-12-28 19:35:37 at MongoDB.Driver.Core.WireProtocol.Messages.Encoders.BinaryEncoders.ReplyMessageBinaryEncoder`1.ReadMessage() + 0x210
2024-12-28 19:35:37 at MongoDB.Driver.Core.Connections.BinaryConnection.ReceiveMessageHelper.DecodeMessage(IByteBuffer, IMessageEncoderSelector, CancellationToken) + 0x135
2024-12-28 19:35:37 at MongoDB.Driver.Core.Connections.BinaryConnection.ReceiveMessage(Int32, IMessageEncoderSelector, MessageEncoderSettings, CancellationToken) + 0x14d
2024-12-28 19:35:37 at MongoDB.Driver.Core.WireProtocol.CommandUsingQueryMessageWireProtocol`1.Execute(IConnection, CancellationToken) + 0x173
2024-12-28 19:35:37 at MongoDB.Driver.Core.Connections.HelloHelper.GetResult(IConnection, CommandWireProtocol`1, CancellationToken) + 0x50
2024-12-28 19:35:37 at MongoDB.Driver.Core.Connections.ConnectionInitializer.SendHello(IConnection, CancellationToken) + 0x105
2024-12-28 19:35:37 at MongoDB.Driver.Core.Connections.BinaryConnection.OpenHelper(CancellationToken) + 0x93
2024-12-28 19:35:37 --- End of inner exception stack trace ---
2024-12-28 19:35:37 at MongoDB.Driver.Core.Connections.BinaryConnection.OpenHelper(CancellationToken) + 0x167
2024-12-28 19:35:37 at MongoDB.Driver.Core.Connections.BinaryConnection.Open(CancellationToken) + 0x17e
2024-12-28 19:35:37 at MongoDB.Driver.Core.Servers.ServerMonitor.InitializeConnection(CancellationToken) + 0x57f
2024-12-28 19:35:37 at MongoDB.Driver.Core.Servers.ServerMonitor.Heartbeat(CancellationToken) + 0x174", LastHeartbeatTimestamp: "2024-12-29T00:35:37.8947163Z", LastUpdateTimestamp: "2024-12-29T00:35:37.8947163Z" }] }.
System.MissingMethodException: No suitable constructor found for serializer type: 'MongoDB.Bson.Serialization.Serializers.ExpandoObjectSerializer