Search code examples
c#visual-studio-2010dllexecutabledllnotfoundexception

Running a C# executable outside of folder containing external library


I have a C# program that uses an external opensource library that I downloaded from the internet, specifically openxml to create excel files. Now I want to run my executable files on computers that do not have this library installed.

I already know that I can have visual studios to make a copy of the library in either the debug or release folder by setting the copy local property to true, and I am doing this.

The problem is that now the executable file can be run on other computers and generate excel files, but the executable file has to be run in the debug or release folder where the library is saved.

When I try to copy the executable file and run it outside of the folder an exception is thrown telling me that the library cannot be found, how do I make it find the library when running the executable outside of the folder?

Thanks,

-Jake


Solution

  • There should be several options that should work.

    The problem is that the library is not in the path.

    This might help. "http://msdn.microsoft.com/en-us/library/vstudio/6taasyc6%28v=vs.100%29.aspx". You would just need to always have the library in the same location.

    You could add the it to the path variable (though this could cause conflicts elsewhere). You could add the folder to the temporary path, i.e. the console whenever it starts up. You could add it to the relative path "Visual Studio: how to set path to dll?"

    Hopefully that helps