== compile command ==
csc -r:"../Newtonsoft.Json.dll" test.cs
== exec command ==
mono test.exe
== exec result : dependency error ==
System.IO.FileNotFoundException: Could not load file or assembly 'Newtonsoft.Json, Version=11.0.0.0, Culture=neutral,
PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies.
"Newtonsoft.Json.dll" this file is located in parent path. so I added a reference about dll and compile succeeded, but when I executed the exe file, it failed to get dll reference I added.
And when I put cs file and dll file together in the same directory, it worked very well, but that's not what I wanted.
Is there a solution to add a reference from dll file which is located in parent path using command line interface?
I used csc for compiler and mono for execution.
Thanks.
References are pathless. What that means is that wherever the assembly resides, all your program knows is that it has a reference to
Newtonsoft.Json, Version=x.x.x.x, Culture=...and so on. You can do some things with the application configuration (application.configormyprogram.exe.config) to organize things into subfolders (using theprobingsetting) or specify a URL location for the file (using thecodebasesetting). You can set up the environment to change the search path and so on.Or you can add some runtime code that allows you to override the default behavior and the call
Assembly.LoadFromto provide a full path to the file. You can either do it as part of your initialization or in a handler for theAppDomain.AssemblyResolveevent - which is generally better method since it will only be called when the assembly is actually needed.For example:
Of course you can add your own code to the
Resolvemethod to search pretty much anywhere, just as long as you don't get caught in a resolution loop. I've used theAssemblyResolveevent to do fun things like loading assemblies from compressed resources.