1

I've got a web app that needs to use an unmanaged DLL file.

I'm trying to use the solution suggested on this related question.

The problem that I'm encountering is that the unmanaged DLL is trying to be loaded before the Application_Start of my global.asax file, which is setting my path to include the location of the unmanaged DLL file, therefore the app crashes immediately.

I would really like to keep the act of setting the PATH in my code so that my solution can be deployed to a new server without having to have local access to setup the PATH outside of publishing my solution.

Is there someway that I can force my Application_Start code to execute prior to my other DLL files being loaded?

Community
  • 1
  • 1
Richard West
  • 2,166
  • 4
  • 26
  • 40

1 Answers1

1

Please don't change the PATH environment variable from within an ASP.NET application. This could cause the web server to fail in bizarre ways.

The general accepted way for developers to consume unmanaged libraries from within an ASP.NET application is to put the unmanaged .dll into a subfolder underneath bin, then call LoadLibrary, passing in the full path to the module.

Levi
  • 32,628
  • 3
  • 87
  • 88
  • Levi, Can you provide a link to, or an example of, how this would be called? – Richard West Mar 12 '14 at 18:08
  • The advice I'm stumbling across suggests the opposite: Keep native DLLs out of the bin directory at all costs, and modify the PATH environment variable so they'll get loaded. This seems the most maintainable especially for [large native APIs](http://www.gdal.org/) with lots of DLLs and a complex dependency tree. What bizarre failures are your referring to? – Phil Dec 29 '16 at 22:39