LoadLibraryW call hangs in IIS

I am creating an MVC 5 web application that makes some P / Invoke calls in an unmanaged library (loaded via the LoadLibraryW function).

This all works well in visual studio with IIS Express, but as soon as I publish it and run it with a local IIS instance, the LoadLibraryW function call hangs indefinitely.

To make sure the problem is not my unmanaged library, I created a new "dummy" with a simple message field in the DllMain function, but it also hangs ...

I've tried a lot of things, from enabling 32 bit in AppPool, changing AppPool user, etc.

AppPool works in integrated mode and runs on a Windows 10 computer.

Is there any configuration or special permissions for p / invoke calls inside IIS that I am missing?

This is how I P / Call the LoadLibraryW function:

[DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)]
private static extern IntPtr LoadLibraryW(string fileName);

var moduleHandle = LoadLibraryW(@"c:\dll\interop.dll"); // This call hangs forever


Is it related to CAS? The AppPool.NET Application Trust Levels are set to Full (Internal) and I even changed the AppPool ID to LocalSystem, so I don't understand.

Has anyone experienced this behavior?


EDIT . I see that the VC ++ file and runtime libraries are loaded through Process Monitor and I don't see any errors there, so this behavior is odd.enter image description here


source to share

1 answer

The real problem was that I had code in a "real" unmanaged library that was saving a file in the % Temp% folder without write permission to do so.

Since this operation did not throw any exceptions and just failed, it took me a while to realize that the subsequent code that was on this successful operation was at some kind of "dead end", so the reason was "hanging".

It now worked under IISExpress because as @AdrianoRepetti stated, IISExpress runs in iterative session mode, so the % Temp% folder was directly linked to the logged in user (under Users {MyUser} \ Local \ Temp ), thus having rights to an entry for this user.

When running under IIS, the % Temp% folder becomes the \ Windows \ Temp folder , and there you need to grant IIS_USRS group permissions to write to it.

While trying to figure out what the problem was, I created an unmanaged "dummy" library which, instead of leading me in the right direction, made me think that the problem was with the P / Invoke action itself, as this "dummy" library was also hanging when p / invoked (but that was because of the message box code I had in DllMain to warn me that the library was loaded).



All Articles