1

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?

naxtell
  • 11
  • 3
  • you also need to give permissions to the directory base on pool windows user name to been able to read that directory -> https://stackoverflow.com/questions/16677887/how-to-set-correct-file-permissions-for-asp-net-on-iis/16678016#16678016 – Aristos Apr 09 '21 at 19:38
  • @Aristos I forgot to include that, but I tried giving them full permission. I'll add that above. – naxtell Apr 09 '21 at 19:45
  • 1
    no full permissions - follow the correct permissions given by the correct pool id – Aristos Apr 09 '21 at 22:58
  • @Aristos I have downgraded IUSR and {website name user} to Read permissions as your post suggests. This doesn't solve my issue. The web application still does not look in C:\InstallLocation to load the child assemblies. – naxtell Apr 10 '21 at 13:13
  • read and execute in this case - have in mind that the iis is running as a totally different user - it maybe not on the path list – Aristos Apr 10 '21 at 20:11
  • That's what I meant, read & execute. – naxtell Apr 12 '21 at 17:01
  • Do you have check that is the correct 32 or 64 bit the pool ? the same with the dlls – Aristos Apr 12 '21 at 23:56
  • I have enabled 32 bit apps on the pool, that was the first error that was shown. I'm not aware of another setting in IIS to have the pool be 32 vs 64 bit, only to have it allow 32 bit apps. I am also building the website with the x86 platform selected, but I'm not sure that it matters. – naxtell Apr 13 '21 at 13:56
  • the extra dll must be build the same as your site - or the site must be build as the dll – Aristos Apr 13 '21 at 22:17

0 Answers0