F#交互式,对DLL引用的API限制 [英] F# interactive, API restriction on dll referencing
问题描述
您如何解决如下所示的错误消息?
How do you solve the error message that looks like this?
`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.
触发它的代码可能看起来像这样:
Code that triggers it, might look like this:
#r @"..\packages\NLog.2.0.0.2000\lib\net20\NLog.dll"
NLog.Config.SimpleConfigurator.ConfigureForConsoleLogging()
推荐答案
似乎FSI不会从给定的DLL中加载,而不会按名称加载,因此这可以解决问题:
It seems that FSI won't load from the given DLL other than by name, so this would sort the problem out:
#I @"..\packages\NLog.2.0.0.2000\lib\net20"
#r @"NLog.dll"
NLog.Config.SimpleConfigurator.ConfigureForConsoleLogging()
#I
表示将该文件夹添加到加载路径
#I
means to add that folder to the load-path
#r
表示通过dll路径引用;专注于名字.这意味着FSI将首先使用文件名,在系统范围内的搜索路径中查找,然后才尝试使用#r
之后的字符串作为相对于目录的提示.
#r
means to reference by dll-path; focusing on name. This means that FSI will use the file name first, looking in the system-wide search path and only then try to use the string after #r
as a directory-relative hint.
因此,通过这种方式,您可以从指定目录而不是系统范围的目录中加载NLog.
So by doing it this way, you make the NLog load from your specified directory rather than a system-wide one.
这篇关于F#交互式,对DLL引用的API限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!