你如何解决看起来像这样的错误消息?
`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.
Run Code Online (Sandbox Code Playgroud)
触发它的代码可能如下所示:
#r @"..\packages\NLog.2.0.0.2000\lib\net20\NLog.dll"
NLog.Config.SimpleConfigurator.ConfigureForConsoleLogging()
Run Code Online (Sandbox Code Playgroud)
似乎FSI不会从名称之外的给定DLL加载,所以这会解决问题:
#I @"..\packages\NLog.2.0.0.2000\lib\net20"
#r @"NLog.dll"
NLog.Config.SimpleConfigurator.ConfigureForConsoleLogging()
Run Code Online (Sandbox Code Playgroud)
#I 意味着将该文件夹添加到加载路径
#r表示通过dll-path引用; 专注于名字.这意味着FSI将首先使用文件名,查看系统范围的搜索路径,然后尝试使用后面的字符串#r作为目录相对提示.
因此,通过这种方式,您可以从指定的目录而不是系统范围的目录中加载NLog.