我正在使用 .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/