F# interactive, API restriction on dll referencing

别说谁变了你拦得住时间么 提交于 2019-12-23 09:32:04

问题


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()

回答1:


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 means to add that folder to the load-path

#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.

So by doing it this way, you make the NLog load from your specified directory rather than a system-wide one.



来源:https://stackoverflow.com/questions/9465214/f-interactive-api-restriction-on-dll-referencing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!