fsprojects / FSharp.Json

F# JSON Reflection based serialization library
Apache License 2.0
226 stars 26 forks source link

The namespace 'Json' is not defined. When use it in Fake script #12

Closed albertwoo closed 5 years ago

albertwoo commented 6 years ago

When I use this package in Fake script, it works fine when I sent to F# interactive, but failed when I run fake run script.fsx and the error is like "The namespace 'Json' is not defined."

vsapronov commented 6 years ago

I guess that you have not included the assembly with #r... in your fsx script. Could you please paste your script here?

albertwoo commented 6 years ago

My script reference is like this:

#load ".fake/build.fsx/intellisense.fsx"
#if !FAKE
#r "netstandard"
#endif

open FSharp.Json

let empty  = Json.serialize

The paket.dependencies file is look like:

// [ FAKE GROUP ]
group Build
    storage none
    source https://api.nuget.org/v3/index.json
    nuget Fake.DotNet.Cli
    nuget Fake.IO.FileSystem
    nuget Fake.Core.Target
    nuget FSharp.Data 3.0.0-beta4
    nuget Newtonsoft.Json

fake will handle intellisense.fsx then #load intellisense_lazy.fsx, in there the #r will load the FSharp.json automatically.

Problem is if I do the same way with Newtonsoft.Json, it works but failed with FSharp.Json.

vsapronov commented 6 years ago

I see that you reference Newtonsoft.Json in your paket.dependencies. FSharp.Json is NOT Newtonsoft.Json. FSharp.Json is a separate package.

albertwoo commented 6 years ago

Sorry for the misunderstanding, what I mean is that if I replace Fsharp.Json with Newtonsoft.Json everything is working fine. But If I use Fsharp.Json then the error happens.

vsapronov commented 6 years ago

OK, I see. I need to investigate more. I suspect the netstandard might be the reason for your problems. I haven't build FSharp.Json in netstandard yet. But I think I should as this issue (still open) suggests: https://github.com/vsapronov/FSharp.Json/issues/7

vsapronov commented 5 years ago

Please try to use release 0.3.4. It's built for .Net Standard, now it should work.

albertwoo commented 5 years ago

Thanks, it works great!