DLL dependency from different installation folder not found in ASP.NET website

127 Views Asked by At

I have created a .NET Framework 4.7.2 website with a WCF service. To expose data through this service, I have to reference a third party DLL with Copy Local = False from C:\InstallLocation. The website is loading this DLL at runtime, but I get an error when accessing functionality in the DLL that requires it to load a secondary DLL in the same InstallLocation folder. I verified with Process Monitor that W3WP.exe is finding the primary DLL at C:\InstallLocation, but that W3WP.exe fails to look in C:\InstallLocation at all for the secondary DLL. The application error is the expected,

Could not load file or assembly '[assembly-info-ommitted]' or one of its dependencies. The system cannot find the file specified.

I also tested the exact same type of reference in a Console Application which worked without issue. Process Monitor showed the executable looking in C:\InstallLocation for the secondary DLL.

Is there a way to configure the .NET web app to allow the process to look in the same directory as the referenced, primary DLL? I have tried the following without (full) success:

  • Adding C:\InstallLocation to my system Path (and restarted). Seemed to have no affect. I verified on application start that the added path did appear in Environment.GetEnvironmentVariable("PATH").
  • Moved C:\InstallLocation into my web root and tried <probing privatePath="CopiedLocation". This got past the initial DLL reference issues, but still showed an error but on a different dependency for a different DLL. I don't think this will be a viable workaround.
  • Movied C:\InstallLocation to the bin folder and commented out . Same result as the above.
  • Gave the app pool user full permission to C:\InstallLocation. Users: IIS APPPOOL\{web site name}, IUSR, IIS_IUSRS

Edit

I have implemented an initializer as shown here, https://stackoverflow.com/a/16867088/2544926. I have changed the code to check if a DLL exists in C:\InstallLocation to load the DLL from that folder. From Process Monitor output, it would seem this is getting me closer. However, I am seeing an error later in the process. Here is the error that I am seeing now (multi-level exception).

The type initializer for '<Module>' threw an exception.

A nested exception occurred after the primary exception that caused the C++ module to fail to load.

The type initializer for '<Module>' threw an exception.

The C++ module failed to load during vtable initialization.

Could not load file or assembly 'XYZ, Version=N.N.N.N.N, Culture=neutral, PublicKeyToken=NNNNNNNNN' or one of its dependencies. The system cannot find the file specified.

Interestingly, in my custom Assembly Initializer code, I see XYZ.DLL being loaded from C:\InstallLocation. Is it possible this C++ module is attempting to load it differently or in a way that isn't supported by ASP.NET?

0

There are 0 best solutions below