Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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()
like image 703
Henrik Avatar asked Feb 27 '12 12:02

Henrik


1 Answers

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.

like image 147
Henrik Avatar answered Nov 15 '22 11:11

Henrik