7

I have asp.net core application which uses mongodb as backend.

Recently I have started getting this error without any changes in database or code.

Here is complete error I am getting when I browse my API

An error occurred while starting the application.
InvalidOperationException: Record reader index out of sync.
DnsClient.DnsRecordFactory.GetRecord(ResourceRecordInfo info)

DnsResponseException: Unhandled exception
DnsClient.LookupClient.ResolveQuery(DnsMessageHandler handler, DnsRequestMessage request, Audit continueAudit)

InvalidOperationException: Record reader index out of sync.
DnsClient.DnsRecordFactory.GetRecord(ResourceRecordInfo info)
DnsClient.DnsMessageHandler.GetResponseMessage(ArraySegment<byte> responseData)
DnsClient.DnsUdpMessageHandler.Query(IPEndPoint server, DnsRequestMessage request, TimeSpan timeout)
DnsClient.LookupClient.ResolveQuery(DnsMessageHandler handler, DnsRequestMessage request, Audit continueAudit)

Show raw exception details
DnsResponseException: Unhandled exception
DnsClient.LookupClient.ResolveQuery(DnsMessageHandler handler, DnsRequestMessage request, Audit continueAudit)
DnsClient.LookupClient.Query(DnsQuestion question)
MongoDB.Driver.Core.Configuration.ConnectionString.Resolve()
MongoDB.Driver.MongoUrl.Resolve()
MongoDB.Driver.MongoClientSettings.FromUrl(MongoUrl url)
MongoDbGenericRepository.MongoDbContext..ctor(string connectionString, string databaseName)
Microsoft.Extensions.DependencyInjection.MongoDbIdentityBuilderExtensions.AddMongoDbStores<TUser, TRole, TKey>(IdentityBuilder builder, string connectionString, string databaseName)
AspNetCore.Identity.MongoDbCore.Extensions.ServiceCollectionExtension.ConfigureMongoDbIdentity<TUser, TRole, TKey>(IServiceCollection services, MongoDbIdentityConfiguration mongoDbIdentityConfiguration, IMongoDbContext mongoDbContext)
BrightSteps.Web.Api.Extensions.Utility.ConfigureMongoIdentity(IServiceCollection services, MongoDbSettings settings) in Utility.cs
BrightSteps.Web.Api.Startup.ConfigureServices(IServiceCollection services) in Startup.cs
Microsoft.AspNetCore.Hosting.ConventionBasedStartup.ConfigureServices(IServiceCollection services)
Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureApplicationServices()
Microsoft.AspNetCore.Hosting.Internal.WebHost.Initialize()
Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()

Show raw exception details
6
  • did you find any solution?
    – user897645
    Commented Mar 5, 2020 at 9:20
  • I mentioned answer below, that worked for me. if you want to use SVR connection string then you might need to update mongodb driver. Commented Mar 5, 2020 at 10:55
  • This github.com/MichaCo/DnsClient.NET/issues/51 should be fixed in the next version. Checkout the 1.3.0 version on nuget.org and let me know if that fixes it
    – MichaC
    Commented Mar 11, 2020 at 15:35
  • @MichaC we are not using DnsClient.net. directly, instead we are using mongo db driver (2.7.0) So will have to wait till they uppdate their dependency Commented Mar 13, 2020 at 5:18
  • @KrunalParmar You'd have to upgrade the mongo driver to at least 2.8.0 to use the newer DnsClient 1.3.0 (which will be compatible to 1.2.0 this time ~~)
    – MichaC
    Commented Mar 14, 2020 at 11:33

2 Answers 2

3

It turns out, that issue was with connection string and my driver version.

C# MongoDB driver is depend on DNSClient.Net Package, which is uses to do DNS lookup for connection string.

Since I was using older version of driver it does not support SVR connection string of mongo db and I have to use Non SVR Connection string in mongodb.

1
  • Thanks! I've used the latest DnsClient 1.3.1 and it works again fine. I'm wondering why the mongodb guys don't update their references in their driver asap. Commented Apr 2, 2020 at 8:24
0

This seems be a bug in the DnsClient which MongoDb.Driver takes a dependency on. https://github.com/MichaCo/DnsClient.NET/issues/51

To fix you can upgrade to the latest DnsClient (1.3.1 at time of writing) https://www.nuget.org/packages/DnsClient/1.3.1

Or if you are in a position to update your MongoDb.Driver package you can update that. The latest (2.10.3 atm) includes the updated DnsClient. https://www.nuget.org/packages/mongodb.driver

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.