C# MongoClient 在第二次请求后抛出 DnsResponseException
C# MongoClient throws DnsResponseException after second request
我在 Atlas 上有一个 MongoDB,我正在从我的 ASP.NET Core MVC 应用程序中查询它。
在我的上下文中 class 我正在从构造函数中初始化 MongoClient,如下所示:
var client = new MongoClient(settings.Value.ConnectionString);
if (client != null)
{
_database = client.GetDatabase(settings.Value.DatabaseName);
}
存储库 class 正在作为临时服务注入到我的控制器中
services.AddTransient<IMovieRepository, MovieRepository>();
如果我尝试从该数据库的集合中获取某些内容,第一次尝试时一切正常。如果我刷新我的页面,它会尝试再次创建 MongoClient 并失败,并向我抛出 DnsResponseException
。之后,我必须等待一分钟左右,它会再次运行一次。 Robo3T 让我想做多少就做多少个连续查询,所以我猜问题只能出在 C# MongoClient 上...
这是我得到的完整异常:
;; Error: Cannot read byte 269, out of range.
System.IndexOutOfRangeException: Cannot read byte 269, out of range.
at DnsClient.DnsDatagramReader.ReadByte()
at DnsClient.DnsDatagramReader.ReadLabels()
at DnsClient.DnsDatagramReader.ReadQuestionQueryString()
at DnsClient.DnsRecordFactory.ReadRecordInfo()
at DnsClient.DnsMessageHandler.GetResponseMessage(ArraySegment`1 responseData)
at DnsClient.DnsUdpMessageHandler.Query(IPEndPoint server, DnsRequestMessage request, TimeSpan timeout)
at DnsClient.LookupClient.ResolveQuery(IReadOnlyCollection`1 servers, DnsMessageHandler handler, DnsRequestMessage request, Boolean useCache, LookupClientAudit continueAudit)
;; Error: Cannot read byte 269, out of range.
System.IndexOutOfRangeException: Cannot read byte 269, out of range.
at DnsClient.DnsDatagramReader.ReadByte()
at DnsClient.DnsDatagramReader.ReadLabels()
at DnsClient.DnsDatagramReader.ReadQuestionQueryString()
at DnsClient.DnsRecordFactory.ReadRecordInfo()
at DnsClient.DnsMessageHandler.GetResponseMessage(ArraySegment`1 responseData)
at DnsClient.DnsUdpMessageHandler.Query(IPEndPoint server, DnsRequestMessage request, TimeSpan timeout)
at DnsClient.LookupClient.ResolveQuery(IReadOnlyCollection`1 servers, DnsMessageHandler handler, DnsRequestMessage request, Boolean useCache, LookupClientAudit continueAudit)
有谁知道我为什么会收到此异常以及如何解决它?
谢谢。
我有 3 天的错误,已经绝望地将我的 DNS 设置更改为:
已解决! ♂️
我在 Atlas 上有一个 MongoDB,我正在从我的 ASP.NET Core MVC 应用程序中查询它。
在我的上下文中 class 我正在从构造函数中初始化 MongoClient,如下所示:
var client = new MongoClient(settings.Value.ConnectionString);
if (client != null)
{
_database = client.GetDatabase(settings.Value.DatabaseName);
}
存储库 class 正在作为临时服务注入到我的控制器中
services.AddTransient<IMovieRepository, MovieRepository>();
如果我尝试从该数据库的集合中获取某些内容,第一次尝试时一切正常。如果我刷新我的页面,它会尝试再次创建 MongoClient 并失败,并向我抛出 DnsResponseException
。之后,我必须等待一分钟左右,它会再次运行一次。 Robo3T 让我想做多少就做多少个连续查询,所以我猜问题只能出在 C# MongoClient 上...
这是我得到的完整异常:
;; Error: Cannot read byte 269, out of range.
System.IndexOutOfRangeException: Cannot read byte 269, out of range.
at DnsClient.DnsDatagramReader.ReadByte()
at DnsClient.DnsDatagramReader.ReadLabels()
at DnsClient.DnsDatagramReader.ReadQuestionQueryString()
at DnsClient.DnsRecordFactory.ReadRecordInfo()
at DnsClient.DnsMessageHandler.GetResponseMessage(ArraySegment`1 responseData)
at DnsClient.DnsUdpMessageHandler.Query(IPEndPoint server, DnsRequestMessage request, TimeSpan timeout)
at DnsClient.LookupClient.ResolveQuery(IReadOnlyCollection`1 servers, DnsMessageHandler handler, DnsRequestMessage request, Boolean useCache, LookupClientAudit continueAudit)
;; Error: Cannot read byte 269, out of range.
System.IndexOutOfRangeException: Cannot read byte 269, out of range.
at DnsClient.DnsDatagramReader.ReadByte()
at DnsClient.DnsDatagramReader.ReadLabels()
at DnsClient.DnsDatagramReader.ReadQuestionQueryString()
at DnsClient.DnsRecordFactory.ReadRecordInfo()
at DnsClient.DnsMessageHandler.GetResponseMessage(ArraySegment`1 responseData)
at DnsClient.DnsUdpMessageHandler.Query(IPEndPoint server, DnsRequestMessage request, TimeSpan timeout)
at DnsClient.LookupClient.ResolveQuery(IReadOnlyCollection`1 servers, DnsMessageHandler handler, DnsRequestMessage request, Boolean useCache, LookupClientAudit continueAudit)
有谁知道我为什么会收到此异常以及如何解决它?
谢谢。
我有 3 天的错误,已经绝望地将我的 DNS 设置更改为:
已解决! ♂️