I created a program (C#) that use a data base file for work.
I used a string to represents the path of this file (returned by the Path.GetDirectoryName() function) and worked before I published with Visual Studio.
So I tested the executable file generated by the publish method, unfortunately, doesn't work. I investigated the problem and I discovered that this function (Path.GetDirectoryName()) returned a null value for my string path. Why this function works before the publish method and doesn't after?
The block of code that I tried:
public class CargaDao
{
static private string caminhoDoBanco = "";
public void inicializarBanco()
{
string diretorioBase = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
caminhoDoBanco = Path.Combine(diretorioBase, "Gollog.db");
}
}
// there is more methods of course but is not relevant for the moment.
but the string, like I said, get a null value.
This problem generated other problems like an error when I use Path.Combine() because my string is passed for this function.
Path.GetDirectoryName()is returning null, what are you passing into it? dotnetfiddle.net/TKQG8B