F# 类型提供程序依赖项解析 - "Could not load file or assembly..."

F# Type Provider dependency resolution - "Could not load file or assembly..."

我在尝试使用我的类型提供程序时遇到 "Could not load file or assembly... ... The system could not find the file specified" 错误。

构建消费应用程序时出现错误,但在构建之前未在 visual studio 中显示为 'red squiggly'。

我已经在下面复制了我的 TP,但问题出现在 Database.listDbs 调用中,我强烈怀疑问题不是下面的代码,而是我如何打包依赖项。

我调入 Microsoft.Azure.DocumentDB 包,而后者又依赖于 Newtonsoft.Json。是找不到的Newtonsoft.Json包。我正在使用 Paket 来管理依赖项并进行重定向。

完整代码(包括所有 paket 文件)在 github 此处:https://github.com/stewart-r/AzureDocumentDbTypeProvider/tree/dependency-issue

我发现 this question 这看起来非常相似,但解决方案没有任何区别。

我的TP代码如下:

namespace ProviderImplementation

open ProviderImplementation.ProvidedTypes
open Microsoft.FSharp.Core.CompilerServices
open System.Reflection
open System
open Config
open Database

[<TypeProvider>]
type public DocumentDbTypeProvider(config: TypeProviderConfig) as this = 
    inherit TypeProviderForNamespaces()

    let thisAssembly = Assembly.GetExecutingAssembly()
    let docDbType = ProvidedTypeDefinition(thisAssembly,namespaceName,"DocumentDbTypeProvider", baseType = Some typeof<obj>)

    let initFn (typeName : string) (args : obj []) = 
        let acProvidedType = ProvidedTypeDefinition(thisAssembly, namespaceName, typeName, baseType = Some typeof<obj>)
        acProvidedType.AddMember(ProvidedConstructor(parameters = [], InvokeCode = (fun args -> <@@ null @@>)))

        let getDbProperties () = 
            Database.listDbs (args.[0] :?> string) (args.[1]:?> string)
            |> List.map(fun d -> new ProvidedProperty(d.Name, typeof<string>, IsStatic = true, GetterCode = (fun _ -> <@@ "Test db name" @@>)))
        acProvidedType.AddMembers(getDbProperties())
        acProvidedType

    let parameters = 
        [ ProvidedStaticParameter("accountEndPointUri", typeof<string>, String.Empty)
          ProvidedStaticParameter("accountKey", typeof<string>, String.Empty)]

    do
        docDbType.DefineStaticParameters(parameters,initFn)
        this.AddNamespace(namespaceName,[docDbType])

[<TypeProviderAssembly>]
do ()

您是否尝试过确保您的 "TP dependencies are located in the same folder that the TP itself resides in"?

听起来您遇到的问题与此答案中描述的相同: (引自这个答案)

这是绑定重定向问题 - 您需要处理 BR inside 类型提供程序。或者,您可以将依赖项限制为直接依赖项所需的 minimum 版本,例如文档数据库。