Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-3755

ObjectId serialization to JSON fails with PlatformNotSupportedException (Web Assembly)

    • Type: Icon: Bug Bug
    • Resolution: Gone away
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: 2.13.0
    • Component/s: None
    • None
    • Environment:
      Windows 10 using Visual Studio 2019, running application in the IIS Express instance for debugging.

      When I try to serialize an object that has ObjectId defined as a field, I get the PlatformNotSupportedException as the serializer tries to execute System.Diagnostics.Process which seems to be unsupported in .Net 5:

       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 ---
         at System.Text.Json.JsonPropertyInfo`1[[System.Int32, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].GetMemberAndWriteJson(Object obj, WriteStack& state, Utf8JsonWriter writer)
         at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1[[MongoDB.Bson.ObjectId, MongoDB.Bson, Version=2.13.0.0, Culture=neutral, PublicKeyToken=null]].OnTryWrite(Utf8JsonWriter writer, ObjectId value, JsonSerializerOptions options, WriteStack& state)
         at System.Text.Json.Serialization.JsonConverter`1[[MongoDB.Bson.ObjectId, MongoDB.Bson, Version=2.13.0.0, Culture=neutral, PublicKeyToken=null]].TryWrite(Utf8JsonWriter writer, ObjectId& value, JsonSerializerOptions options, WriteStack& state)
         at System.Text.Json.JsonPropertyInfo`1[[MongoDB.Bson.ObjectId, MongoDB.Bson, Version=2.13.0.0, Culture=neutral, PublicKeyToken=null]].GetMemberAndWriteJson(Object obj, WriteStack& state, Utf8JsonWriter writer)
         at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1[[CPM.Auth.Models.User, CPM.Auth, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].OnTryWrite(Utf8JsonWriter writer, User value, JsonSerializerOptions options, WriteStack& state)

            Assignee:
            dmitry.lukyanov@mongodb.com Dmitry Lukyanov (Inactive)
            Reporter:
            ivari@risk.ee Ivari Horm
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: