f# - 尽管程序正常运行,类型提供程序 'ProviderImplementation.JsonProvider' 仍报告错误

标签 f# .net-core visual-studio-2017 f#-data

我正在使用 .net Core 和 Visual Studio 2017 编写一个服务。我想使用 JSON 进行配置,因此我定义了这样的类型:

type ServiceConfig = JsonProvider<"exampleConfig.json", EmbeddedResource="MyService, exampleConfig.json", SampleIsList = true>

在我的程序中,我像这样加载它:

let conf = ServiceConfig.Load "config.json"

当我运行它时,它工作正常,但在 VS 2017 中我得到一条红色波浪线,错误日志显示:

FS3033 The type provider 'ProviderImplementation.JsonProvider' reported an error in the context of provided type 'FSharp.Data.JsonProvider,Sample="exampleConfig.json",SampleIsList="True",EmbeddedResource="MyService, exampleConfig.json"', member 'Load'. The error: Method 'FSharp.Data.Runtime.BaseTypes.IJsonDocument Create(System.IO.TextReader, System.String)' not found in type ''. This method may be missing in the types available in the target assemblies.

如何摆脱这个问题?

最佳答案

我不确定这就是问题所在,但提供示例文件的绝对路径可能会有所帮助。解决相对路径是类型提供程序中问题的一个持续来源。您可以执行以下操作:

[<Literal>]
let sample = __SOURCE_DIRECTORY__ + "/exampleConfig.json"
type ServiceConfig = 
    JsonProvider< sample, EmbeddedResource="MyService, e
                  xampleConfig.json", SampleIsList = true >

关于f# - 尽管程序正常运行,类型提供程序 'ProviderImplementation.JsonProvider' 仍报告错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53541883/

相关文章:

azure - 使用 Azure Keyvault SignData 进行 SignedXml

c# - .NET Core项目中 `wwwroot`文件夹的图标怎么改?

azure - 如何在使用 Teamcity 自动部署的 .Net Core 应用程序中设置环境变量

c# - 没有参数的 F# 类构造函数 --- 使用 f# 的 filehelpers 时出错

f# - seq.nth 和 seq.item 有什么区别?

f# - 为什么 F# 不将 Currying 编译成单独的函数?

c# - 在控制台应用程序中使用 Serilog 和 ApplicationInsights 时,从不调用 ITelemetryInitializer.Initialize

c# - Visual Studio 2017 cshtml 文件错误

javascript - 将 const 函数代码从 JSX 转换为 TSX

orm - F# 类型提供程序是否会为实现对象关系映射提供良好的基础?