In a C# class library how can I detect when the DLL is about to be unloaded?

3

I need to write a static List to a text file when a DLL is unloaded. I've tried doing this on AppDomain.CurrentDomain.DomainUnload but it crashes with the error "DefaultDataCollection failed: 0x8007001f".

What is the best way to do this?

Thanks,

Joe

c#
dll
asked on Stack Overflow Nov 1, 2011 by JoeS

1 Answer

1

0x8007001f

That's a WIN32 error (the 7 in the middle is FACILITY_WIN32): ERROR_GEN_FAILURE:

A device attached to the system is not functioning.

So you need to look at the exception type and stack trace to get more details of what is failing.

AppDomain.CurrentDomain.DomainUnload

but remember the documentation has the caveat:

This event is never raised in the default application domain.

answered on Stack Overflow Nov 1, 2011 by Richard

User contributions licensed under CC BY-SA 3.0