3

My .NET 4.0 Web services are using libeay32.dll, which is compiled in VS2010 with the /FIXED option in order to be FIPS compliant. This means that libeay32.dll fails to load unless it gets to live in a certain address (0xfb00000). The exception thrown is:

System.DllNotFoundException: Unable to load DLL 'some_dependent_library.dll': Attempt to access invalid address.

The only way I know to help guarantee that libeay32.dll gets the right address is to load it in a Main() method before any other DLLs are loaded (using LoadLibrary() from kernel32.dll). This is an approach that I've used with success in my Windows Services and unit tests. However, in my Web Services, I've put the LoadLibrary in Application_Start() of my Global.asax.cs, but it is still sporadically failing. (I've looked in procmon - lots of other DLLs are loaded first)

Is there any other way that I can ensure that libeay32.dll gets the required address? Is there code I can run when my App Pool starts up, but before Application_Start()?

pduncan
  • 1,330
  • 2
  • 15
  • 26
  • What is the windows error code you get? Also the first thing to check when loading dlls from IIS: does the application pool user have execute right on the dll? – hege Jun 29 '12 at 16:26
  • Thanks for the reply, hege. Yes, the IIS user has the rights to load the DLL. It works sporadically. It just so happens that sometimes, one of my other DLLs randomly takes up the required address space first, according to ASLR. (I've proven this with ProcMon). libeay32.dll looks like it loads in ProcMon, but since 0xfb00000 is used up, it tries to load in a different address, but this fails internally because of the /FIXED option. – pduncan Jul 03 '12 at 13:39

0 Answers0