【问题标题】:The type provider 'ProviderImplementation.JsonProvider' reported an error despite program working尽管程序正常运行,但类型提供程序“ProviderImplementation.JsonProvider”报告了一个错误
【发布时间】:2019-05-01 16:26:51
【问题描述】:

我正在使用 .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 类型提供程序“ProviderImplementation.JsonProvider” 在提供的类型的上下文中报告错误 'FSharp.Data.JsonProvider,Sample="exampleConfig.json",SampleIsList="True",EmbeddedResource="MyService, exampleConfig.json"',成员'加载'。错误:方法 'FSharp.Data.Runtime.BaseTypes.IJsonDocument 在类型中找不到 Create(System.IO.TextReader, System.String)' ''。可用的类型中可能缺少此方法 目标程序集。

我该如何摆脱它?

【问题讨论】:

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


    【解决方案1】:

    我不确定这是否是问题所在,但提供示例文件的绝对路径可能会有所帮助。解析相对路径是类型提供程序中经常出现的问题。您可以执行以下操作:

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

    【讨论】:

    • 不幸的是,这没有帮助。同样的问题。我想我应该整理一个复制这个的例子并将它发布在 github 页面上。
    • 另外,在测试项目中引用它时,测试项目不再编译:The type provider 'ProviderImplementation.JsonProvider' reported an error: An index satisfying the predicate was not found in the collection.
    • 这修复了我在使用dotnet fsi 时的错误。奇怪的是它是必需的。
    【解决方案2】:

    偶然我自己找到了答案。一定是一些 Visual Studio 索引变得不稳定。我的解决方案中的另一个项目有另一个问题,所以我只是对 git 进行了“紧急提交”,使用 git clean -fdx 清理了我的本地工作副本,然后重新加载了解决方案,重建了所有内容,错误就消失了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-30
      • 1970-01-01
      • 2021-01-27
      • 1970-01-01
      • 1970-01-01
      • 2014-07-20
      • 2015-10-05
      • 1970-01-01
      相关资源
      最近更新 更多