0

I'm trying to use DllImport with a .so File in my project, when I use an absolute path, there is not problem, but, when I use just File name, It doesn't work. I checked the output directory and the file is right there next to .exe file, when I tried this in a Console application in Windows it totally works.

So I tried to validate it before use the extern method, something like this:

        if (System.IO.File.Exists("MyFile.so"))
        {
            Functions.MyExternalMethod();
        }

and the external method is:

public static class Functions
{
     [DllImport("MyFile.so")]
     public static extern void MyExternalMethod();
}

And it throw me DllNotFoundException, EVEN WITH THE PREVIOUS VALIDATION!!! obviusly I'm missing something but I don't know What it is.

How can I fix that?

Like said before, an absolute path works but I cant use it. I checked the output directory and the file is right there With the validation, I can see the file is right there but when I tried to use it... it doesn't work.

I expect use the .so like when I use the absolute path and use his functions, but the actual result is an exception.

Carlos
  • 31
  • 1
  • Whilst the file exists, I guess the system does not look in the working directory, which is sensible. I don't know where it looks on Linux, but I'm sure it can be found by search. – David Heffernan May 26 '19 at 09:35
  • I read something about it and, I read the variable LD_LIBRARY_PATH must be changed, to search in my output directory and not in the default one. but, I don't know how I can changed that, and, if I changed the value ALWAYS in ALL aplicattions would happend the same, Can I damage another applications? – Carlos May 27 '19 at 04:11
  • https://www.mono-project.com/docs/advanced/pinvoke/dllnotfoundexception/ – David Heffernan May 27 '19 at 06:25
  • https://www.mono-project.com/docs/getting-started/application-deployment/?fbclid=IwAR2wKvjMao_PaEun49R00W-sIyRyQgu-uYovf6UD4p3dEuZhj7z-JaPy4K8 I found this, and i think is usefull but, I'm totally new in Linux and although I've that information, I don't know how to use it, the link say something about a SCRIPT but, What script?, Where is the script?. also say something about PREFIX or APPLICATION but I don't know what is must to write there... – Carlos May 27 '19 at 20:11

0 Answers0