JoeS
JoeS

Reputation: 231

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

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

Upvotes: 3

Views: 1691

Answers (1)

Richard
Richard

Reputation: 109005

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.

Upvotes: 1

Related Questions