[CSHARP-4551] Avoid using PID when generating ObjectIds Created: 28/Feb/23  Updated: 28/Oct/23  Resolved: 29/Mar/23

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: None
Fix Version/s: 2.19.2

Type: Improvement Priority: Unknown
Reporter: Isaac Borrero Assignee: Dmitry Lukyanov (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to CSHARP-3755 ObjectId serialization to JSON fails ... Closed
Documentation Changes: Not Needed
Documentation Changes Summary:

1. What would you like to communicate to the user about this feature?
2. Would you like the user to see examples of the syntax and/or executable code and its output?
3. Which versions of the driver/connector does this apply to?


 Description   

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 and here).

Are there any plans to fix this?



 Comments   
Comment by Patrick Gilfether [ 18/May/23 ]

b.dhokia@gmail.com Thanks for following up. We'll be releasing this fix in 2.19.2. We're aiming to publish that nuget package this week or early next.

Comment by Bhavik Dhokia [ 18/May/23 ]

So is this resolved in the 2.19.1 nuget available on nuget.org as I'm still facing the same issue.

 

Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: The type initializer for 'MongoDB.Bson.ObjectId' threw an exception.
System.TypeInitializationException: The type initializer for 'MongoDB.Bson.ObjectId' threw an exception.
 ---> System.PlatformNotSupportedException: System.Diagnostics.Process is not supported on this platform.
   at System.Diagnostics.Process.GetCurrentProcess()
   at MongoDB.Bson.ObjectId.GetCurrentProcessId()
   at MongoDB.Bson.ObjectId.GetPid()
   at MongoDB.Bson.ObjectId.CalculateRandomValue()
   at MongoDB.Bson.ObjectId..cctor()
   --- End of inner exception stack trace ---

Comment by Githook User [ 18/May/23 ]

Author:

{'name': 'Dmitry Lukyanov', 'email': 'dmitry.lukyanov@mongodb.com', 'username': 'DmitryLukyanov'}

Message: CSHARP-4551: Avoid using PID when generating ObjectIds. (#1049)
Branch: v2.19.x
https://github.com/mongodb/mongo-csharp-driver/commit/aed0fcc1079cf652deb9a52697d7b788ce8b5c9f

Comment by Bhavik Dhokia [ 25/Apr/23 ]

I also face this issue so looking forward to the release. Any ideas when it will be available on nuget.org as I can't see it available at the moment.

Comment by Githook User [ 29/Mar/23 ]

Author:

{'name': 'Dmitry Lukyanov', 'email': 'dmitry.lukyanov@mongodb.com', 'username': 'DmitryLukyanov'}

Message: CSHARP-4551: Avoid using PID when generating ObjectIds. (#1049)
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/0e8aed203e71c9eac0d388f37c91503ccdebbe3f

Comment by Isaac Borrero [ 28/Feb/23 ]

While I would LOVE, LOVE, LOVE for you to fix this, I understand if its not a priority.  I am trying to determine if I should build a permanent workaround into my project.

Comment by Isaac Borrero [ 28/Feb/23 ]

Yes, the inner exception is 'System.PlatformNotSupportedException', while the outer exception is System.TypeInitializationException.  

Comment by Dmitry Lukyanov (Inactive) [ 28/Feb/23 ]

Hey isaac.borrero@firestar.io, thanks for your report, can you please confirm that you see a "PlatformNotSupportedException" exception in your case?

Generated at Wed Feb 07 21:48:34 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.