Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception thrown when using AutoMap on a document with a Guid identifier #71

Open
Yalpe opened this issue Apr 29, 2024 · 0 comments
Open

Comments

@Yalpe
Copy link

Yalpe commented Apr 29, 2024

Describe the bug
The library will cause the MongoDB driver to throw if the consumer code tries to configure AutoMaps before the MongoStaticInitializer is executed.

To Reproduce
Add this class somewhere.

public class GuidHavingClass
{
    protected GuidHavingClass()
    {
        this.Id = Guid.NewGuid();
    }

    public Guid Id { get; init; }
}

Then add this piece of configuration

services.AddMongo(<snip>).ConfigureStaticOptions(options =>
{
    BsonClassMap.RegisterClassMap<GuidHavingClass>(classMap =>
    {
        classMap.AutoMap();
    });
});

Expected behavior
The library should not use lazy instanciation for the static registrations as it makes it a lot harder to fiddle with it in our own configuration code. For example, we cannot unregister the EnumRepresentationConvention to set it to BsonType.Int32 instead.

Screenshots
Due to the fact that we try to use a Guid as the Id mongo will look for a serializer and add one of it fails to find one.
image

Then once the code tries to create a MongoClient instance the driver will throw
image

Environment (please complete the following information):
any

Additional context
Add any other context about the problem here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant