0

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" }] }.
6
  • I rebuilt container without AOT and looks the problem has been fixed. Still would like to know why AOT breaks mongo driver. Commented Dec 29, 2024 at 1:07
  • You may want to show us the docker file you're using to set this all up. Chances are something in the configuration is not allowing the connections to work correctly. Commented Dec 29, 2024 at 6:53
  • 1
    1) connection from running container works fine (I tested with telnet) 2) after removing AOT setting from project file, everything works fine Commented Dec 29, 2024 at 20:16
  • @Leo can you please add a full runnable minimal reproducible example? Commented Dec 29, 2024 at 21:51
  • you have error related to serialization: System.MissingMethodException: No suitable constructor found for serializer type: 'MongoDB.Bson.Serialization.Serializers.ExpandoObjectSerializer Commented Dec 30, 2024 at 6:50

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.