質問

I'm in DLL hell right now trying to make my code work within the framework of a different application. For the longest time I was thrashing around trying to understand why my methods weren't being called when they were clearly being enqueued to the ThreadPool.

It finally turned out to be that one particular DLL had to be in the same folder as the calling method, or failing to find it, the ThreadPool thread would either die or ditch the job silently (like a ninja).

Obviously, the solution compiled perfectly and threw no errors, as the DLL in question was being built, just to a different folder. This isn't the first time that a ThreadPool thread has just died silently on me because of a misplaced DLL.

  1. What exactly is happening to my threads when they disappear?
  2. How do I figure out that this is happening in the future? Would there be a log file somewhere by any chance?

Some code:

protected void Enqueue()
{
    try
    {
        Task.Run(() => Process());
    }
    catch (Exception ex)
    {
        // Logging code here (no issues)
    }
}

protected void Process()
{
    // A breakpoint here will never be called

    try {       
        // Code that calls into offensive DLL
    }
    catch (Exception e)
    {
        // Logging code
    }
}
役に立ちましたか?

解決

Assuming that Process contains the call to the DLL. If so, the exception is thrown on JIT of process, and so you cannot catch it within Process. Use one more layer of indirection before calling the DLL to be sure of being able to log it.

protected void Enqueue()
{
    try
    {
        Task.Run(() => Process());
    }
    catch (Exception ex)
    {
        // Logging code here (no issues)
    }
}

protected void Process()
{
    try {
        Process2();
    }
    catch (Exception e)
    {
        // Logging code
    }
}

protected void Process2()
{
            // Code that calls into offensive DLL
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top