【问题标题】:F# interactive, API restriction on dll referencingF# 交互式,对 dll 引用的 API 限制
【发布时间】:2012-02-27 12:43:47
【问题描述】:

您如何解决看起来像这样的错误消息?

`Binding session to 'C:\Program Files (x86)\NLog\.NET Framework 4.0\NLog.dll'...

error FS0193: API restriction: The assembly 
'file:///C:\Program Files (x86)\NLog\.NET Framework 4.0\NLog.dll' has 
already loaded from a different location. It cannot be loaded from a 
new location within the same appdomain.

触发它的代码可能如下所示:

#r @"..\packages\NLog.2.0.0.2000\lib\net20\NLog.dll"
NLog.Config.SimpleConfigurator.ConfigureForConsoleLogging()

【问题讨论】:

    标签: f# f#-interactive


    【解决方案1】:

    似乎 FSI 不会从给定的 DLL 加载,而不是按名称加载,所以这可以解决问题:

    #I @"..\packages\NLog.2.0.0.2000\lib\net20"
    #r @"NLog.dll"
    NLog.Config.SimpleConfigurator.ConfigureForConsoleLogging()
    

    #I 表示将该文件夹添加到加载路径

    #r 表示通过 dll-path 引用;专注于名字。这意味着 FSI 将首先使用文件名,查找系统范围的搜索路径,然后才尝试使用 #r 之后的字符串作为相对于目录的提示。

    因此,通过这种方式,您可以从您指定的目录而不是系统范围的目录加载 NLog。

    【讨论】:

    • 我在这里添加了这个答案,因为我在谷歌搜索时找不到它,重新加载交互没有帮助,我不得不猜测我的答案(有效)。所以,谷歌,这里有一些饲料。
    猜你喜欢
    • 1970-01-01
    • 2017-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多