I've inherited a half completed application that seems to use a model that I'm not sure can reliably work.
It is a ASP.NET webservice that on each call loads a unmanaged C++ .DLL using
[DllImport ( "kernel32.dll" , EntryPoint = "LoadLibraryA" )]
public static extern int LoadLibrary( string lpLibFileName );
and then makes a number of calls to it e.g.
[DllImport(@"MyUnamanagedDLL.dll")]
public static extern string DoStuff( );
In the unmanaged C++ .dll it is using a singleton to hold state between calls. This is so that it only has to initialise once and load a bunch of slow stuff from disk and database rather than on each webservice call as this is too slow.
So each call into the unmanaged .dll first calls Getinstance() if the instance is null it initialises it and reloads everything, if not it assumes its ready to go.
FreeLibrary is not being called each time in the webservice as I assume this would cause the unmanaged class to have to be re-initialised each time.
Is this model at all reliable? Can you ensure that if the webservice is shut down that the unmanaged state is cleaned up properly? Can you ensure you will relaible get a valid singleton instance between loadlibrary calls?