Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run mono .exe with the DLL's in a different folder

Tags:

c#

mono

dll

gmcs

dmcs

I compiled the test.cs file (which references a third party library) using the dmcs executable for Mac and the following command line program:

dmcs /out:program.exe test.cs /target:exe /reference:/Users/kevin/path/to/bin/Debug/project.dll 

This compiled with no problems (excluding the /reference argument causes issues). This created a program.exe executable in the current directory. When I tried to run it like this:

mono program.exe

I got the following error:

Unhandled Exception:
System.IO.FileNotFoundException: Could not load file or assembly 'project, Version=3.4.1.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.

The only way I could figure out to solve this was by copying the project.dll file into the directory containing the program.exe file. Once I copied project.dll into the same directory, the program ran correctly.

Is there an extra argument I can pass to mono to specify DLL's in a different program directory? Or, is there a flag I can pass to dmcs to get it to compile the DLL`s directly into the binary?

like image 892
Kevin Burke Avatar asked Dec 25 '12 09:12

Kevin Burke


1 Answers

You can use the probing element in app.config to achieve what you want

<configuration>
   <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
         <probing privatePath="bin;bin2\subbin;bin3"/>
      </assemblyBinding>
   </runtime>
</configuration>

Where you set privatePath to whatever directory you want. http://msdn.microsoft.com/en-us/library/823z9h8w(v=vs.80).aspx

However, unless you specify a sub directory, I'd strongly advice against this. If you really do not want to have the assembly in the same directory, consider linking as Uwe Keim suggested or use the GAC.

Linking: http://www.mono-project.com/Linker

GAC: http://www.mono-project.com/Assemblies_and_the_GAC

like image 100
TimothyP Avatar answered Oct 28 '22 10:10

TimothyP