Category: MongoDB

System.IO.FileLoadException : Could not load file or assembly 'MongoDB.Driver.Legacy, Culture=neutral, PublicKeyToken=null'. Invalid pointer (0x80004003 (E_POINTER))

I setup a set of automated tests for one of my pet projects but annoyingly I came across the following error today: System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation. ----> System.IO.FileLoadException : Could not load file or assembly 'MongoDB.Driver.Legacy, Culture=neutral, PublicKeyToken=null'. Invalid pointer (0x80004003 (E_POINTER)) The solution is to install

Continue Reading

MongoDB and C# decimals

MongoDB used to serialize C# decimals to strings. This wasn't an issue when simply storing and retrieving values. However, if you'd like to search or sort by the value, it makes the value pretty useless. The decimal value would need to be stored both as a decimal (precise number) for use and a double for

Continue Reading

Unit testing MongoDB serialization

If you added custom serializers to your model, you almost certainly want to be able to unit test it. TDD is strongly encouraged here, simply because it is very easy to make mistakes. IBsonSeralizers themselves are not so easy to test and you can make a very legitimate argument they should be made internal and

Continue Reading

Adding custom type converter to MongoDB in C#

I covered how to impelement a custom type converter for MongoDB in my previous article. In this article, I want to cover adding a serializer to MongoDB 'serializer'. There are couple of tricks you can use to make your life easier. Unlike EF Core with its IEntityTypeConfiguration<TType>, MongoDB driver is more static. You can specify

Continue Reading

Custom type converters for MongoDB

I always try to keep my models seperate from the implementation or configuration. EF Core 2.1 added great support for custom type converters with HasConversion. MongoDB also has a support for custom type conversion, though it is not quite as well documented. The basic premise revolves around implementing IBsonSerializer<TType>. Let's suppose I have a Bitrate

Continue Reading

How to resolve: MongoDB.Driver.MongoAuthenticationException: Unable to authenticate using sasl protocol mechanism SCRAM-SHA-1.

I came across this error today whilst trying to deploy my application on Azure. MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server. ---> MongoDB.Driver.MongoAuthenticationException: Unable to authenticate using sasl protocol mechanism SCRAM-SHA-1. As it turns out, MongoDB may have separate databases for authentication and data and therefore it is essential to specify

Continue Reading