dotnet/runtime

System.Text.Json.Serialization.Tests failing with `FileLoadException` on net48 runs

elinor-fung opened this issue · 4 comments

After #65863, these two are failing on net48 runs:

  • System.Text.Json.Serialization.Tests.CacheTests.JsonSerializerOptions_ReuseConverterCaches
  • System.Text.Json.Serialization.Tests.CustomConverterTests.GetConverter_Poco_WriteThrowsNotSupportedException
Child exception:
  System.IO.FileLoadException: Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
   at System.Span`1..ctor(T[] array, Int32 start, Int32 length)
   at System.Text.Json.PooledByteBufferWriter.Dispose()
   at System.Text.Json.JsonSerializer.WriteStringUsingSerializer[TValue](TValue& value, JsonTypeInfo jsonTypeInfo)
   at System.Text.Json.JsonSerializer.Serialize[TValue](TValue value, JsonSerializerOptions options)
   at System.Text.Json.Serialization.Tests.CustomConverterTests.<>c.<GetConverter_Poco_WriteThrowsNotSupportedException>b__321_0()

Build: https://dev.azure.com/dnceng/public/_build/results?buildId=1637814&view=ms.vss-test-web.build-test-results-tab&runId=45326006&paneView=debug&resultId=118036

cc @eiriktsarpalis @layomia

Tagging subscribers to this area: @dotnet/area-system-text-json
See info in area-owners.md if you want to be subscribed.

Issue Details

After #65863, these two are failing on net48 runs:

  • System.Text.Json.Serialization.Tests.CacheTests.JsonSerializerOptions_ReuseConverterCaches
  • System.Text.Json.Serialization.Tests.CustomConverterTests.GetConverter_Poco_WriteThrowsNotSupportedException
Child exception:
  System.IO.FileLoadException: Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
   at System.Span`1..ctor(T[] array, Int32 start, Int32 length)
   at System.Text.Json.PooledByteBufferWriter.Dispose()
   at System.Text.Json.JsonSerializer.WriteStringUsingSerializer[TValue](TValue& value, JsonTypeInfo jsonTypeInfo)
   at System.Text.Json.JsonSerializer.Serialize[TValue](TValue value, JsonSerializerOptions options)
   at System.Text.Json.Serialization.Tests.CustomConverterTests.<>c.<GetConverter_Poco_WriteThrowsNotSupportedException>b__321_0()

Build: https://dev.azure.com/dnceng/public/_build/results?buildId=1637814&view=ms.vss-test-web.build-test-results-tab&runId=45326006&paneView=debug&resultId=118036

cc @eiriktsarpalis @layomia

Author: elinor-fung
Assignees: -
Labels:

area-System.Text.Json, untriaged

Milestone: -

I've disabled the failing tests in #66248, reopening to track the issue.

mrBen commented

Is there a known workaround for this bug?

I get the same exception as described when calling JsonSerializer.Serialize and I'm stuck with .NET Framework at the moment because I'm writing a VS 2019 extension.

Adding <PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.5.3"/> to my .csproj doesn't help, as I also get a System.IO.FileLoadException when I call JsonSerializer.Deserialize, but with version 6.0.0.0.

System.IO.FileLoadException: 'Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. [...]