gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 21:00:42 25 4
gpt4 key购买 nike

我在尝试使用我的类型提供程序时遇到“无法加载文件或程序集... ...系统找不到指定的文件”错误。

错误出现在构建消费应用程序时,但在构建之前不会在 Visual Studio 中显示为“红色波浪线”。

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

我调用 Microsoft.Azure.DocumentDB 包,该包又依赖于 Newtonsoft.Json。这是找不到 Newtonsoft.Json 包。我正在使用 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 ()

最佳答案

这是一个绑定(bind)重定向问题 - 您需要在类型提供程序内部处理 BR。或者,您可以将依赖项限制为直接依赖项所需的最低版本,例如文档数据库。

关于F# 类型提供程序依赖项解析 - "Could not load file or assembly...",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38419979/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com