MongoDB C# BSON not supported in Blazor WebAssembly

The C# BSON creates a ObjectId value with a call to System.Diagnostics.Process.GetCurrentProcess().Id. The Blazor Webassembly framework does not support calls to Process.GetCurrentProcess() (see here and here)

1 Like

Hi, @Isaac_Borrero,

Welcome to the MongoDB Community Forums. Thank you for filing CSHARP-4551 as a feature request. This is a reasonable request and we are discussing when we can schedule this work. Please follow the linked ticket for updates.

Sincerely,
James

Is there any workaround for that? I’m working on a blazor app and wanted to use mongo db with it but the MongoDB.Bson.ObjectId throws an exception when I want to use it.

@James_Kovacs @Tyler_Kaye

Wouldn’t this be a fit for the C# SDK for Realm?

I think the MongoDB Realm C# SDK may work, I’m uncertain if it really works with Blazor yet, but it does work with MAUI which has a lot of the same components.

It might be worth a try to see?

It looks like it should be fixed for MDB usage, but it done actually throw an exception using the driver. I haven’t dived that deep with Blazor on the SDK though, and am curious how Realm can maybe solve this?

I’ve seen that there is a fix for that on github already on master, I’ve downloaded it to continue working. Thanks for your fix, looking forward to the update.

1 Like

The Realm C# SDK uses the MongoDB.Bson package for BSON support. So it would have the same problem as the MongoDB .NET/C# Driver. As noted, we have a fix that will be released in the coming weeks. I don’t have a timeline on exactly when, but I’m glad that you’re able to work around this by compiling from source.

1 Like

I actually didn’t know that about the BSON package, I always thought they were different.

Thank you for explaining that actually.

I would also like to request that Bson-related attributes be moved into a separate library without dependencies. This adds 1.4 MB to the website build. It accounts for 26% of the size of my WASM website.

To share data classes with BsonIdAttribute and the like requires MongoDB.Bson.dll (496 KB) and also MongoDB.Driver.Core.dll (941 KB).

Even with br compression, that’s 155 KB and 280 KB, respectively, added to the website download.

I just downloaded MongoDB.Bson 2.19.2 → I can generate an ObjectId now. Thank you for getting this done. Much appreciated!!!

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.