I have a strange problem. I have written a custom spamfilter in C# .NET 4.6 for personal use. And I put this program up to my Raspberry Pi.
I have tested many times the program, and everything worked fine, but when I created a cronjob I have noticed that the program never writes log.
As I started to test again I have find out, that the problem is, when I start the program from the program's base dir, it works fine:
> cd path/to/program
> mono program.exe
> mono /absolute/path/to/program/program.exe
> mono /home/user/program/program.exe
The current directory is correct, it is the current directory of where you are starting the process, and that process is
mono in this case, and not the location of the CIL-based assembly that mono is loading.
What is sounds like you want is the path of the
This works on x-plat (Windows/Linux/macOS):
string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); Console.WriteLine(path);