views:

48

answers:

2

We have an ASP.NET web application, which is a C# DLL, that references a C++/CLI DLL, that links against some native static libs.

When we edit the web.config file, the appdomain unloads itself as expected, however at the next web request the application crashes with some access violation exception from our native code.

Further investigation has shown that as soon when the app domain "unloads", the w3wp.exe process actually lives on, and it only unloads our C# DLL (and not our C++/CLI DLL). This is probably why we're getting these exceptions.

How can we stop this madness? Can we get ASP.NET to completely recycle the w3wp process upon web.config update? Can we get ASP.NET to actually unload all of our DLLs if w3wp lives on?

A: 

Create a wrapper assembly and manually GetModuleHandle + FreeLibrary when the assembly / appDomain is recycled.

It would cause problems if you create Application Domains manually or use one Application Pool in IIS for multiple applications, though.

Jaroslav Jandek
Wrapper assembly around what?
A "FreeDll" Wrapper (in C#) around whatever DLL is not getting freed (for convenience).
Jaroslav Jandek
A: 

Couldn't find any solution better than calling Environment.Exit(0) at the end of Application_End.