Tarmil / FSharp.SystemTextJson

System.Text.Json extensions for F# types
MIT License
329 stars 45 forks source link

FSharp.Core 4.7 not found when calling `Serialize` from `net48` project using F#6 #105

Open tymokvo opened 2 years ago

tymokvo commented 2 years ago

Hello,

I'm trying to use a method that calls JsonSerializer.Serialize in one of my libraries from a .fsx script. The script looks like:

#r "MyLib.dll"
open MyLib

let m = Map.ofArray [|("a", 1)|]

MyLib.serialize m

The library references "FSharp.SystemTextJson" Version="0.17.4"

Whenever I hit the code path that calls Serialize I get the traceback:

Could not load file or assembly 'FSharp.Core, Version=4.7.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
   at System.Text.Json.Serialization.JsonFSharpConverter.CanConvert(Type typeToConvert)
   at System.Text.Json.JsonSerializerOptions.GetConverter(Type typeToConvert)
   at System.Text.Json.JsonSerializerOptions.DetermineConverterForProperty(Type parentClassType, Type runtimePropertyType, PropertyInfo propertyInfo)
   at System.Text.Json.JsonClassInfo.GetImplementedCollectionType(Type parentClassType, Type queryType, PropertyInfo propertyInfo, JsonConverter& converter, JsonSerializerOptions options)
   at System.Text.Json.JsonClassInfo.GetClassType(Type type, JsonSerializerOptions options)
   at System.Text.Json.JsonClassInfo..ctor(Type type, JsonSerializerOptions options)
   at System.Text.Json.JsonSerializerOptions.GetOrAddClass(Type classType)
   at System.Text.Json.WriteStackFrame.Initialize(Type type, JsonSerializerOptions options)
   at System.Text.Json.JsonSerializer.WriteCore(Utf8JsonWriter writer, PooledByteBufferWriter output, Object value, Type type, JsonSerializerOptions options)
   at System.Text.Json.JsonSerializer.WriteCore(PooledByteBufferWriter output, Object value, Type type, JsonSerializerOptions options)
   at System.Text.Json.JsonSerializer.WriteCoreString(Object value, Type type, JsonSerializerOptions options)
   at System.Text.Json.JsonSerializer.Serialize[TValue](TValue value, JsonSerializerOptions options)

Even though FSharp.Core 6.0 is available on the probing path and the NuGet depedencies indicate that this should work with F# >= 4.7. Thanks!