2

我的 azure webjob 似乎正在终止而没有抛出异常,我迷路了。

我的网络作业是按需(或计划)运行的,并且依赖于我的网站 DLL(和 MVC 应用程序)。它调用它来完成大部分工作,其中包括使用实体框架数据库和对其他几个站点进行 REST 调用。大多数工作都是异步完成的。用于完成这项工作的大部分代码也可以毫无问题地从站点的其他部分调用,不用说,Web 作业在本地运行时可以完美运行。

Web 作业终止,并且似乎没有抛出异常,而且似乎无法调试不属于连续运行类型的 Web(?)。因此,我的调试主要是 Console.WriteLine 种类。由于这个原因和异步性,我无法确定它崩溃的确切位置 - 我以为是在访问数据库时,但在弄乱它之后,数据库访问开始工作......呃。我的下一个最佳猜测是它在等待或其他异步管道期间死亡。但是,它确实会在两个 try/catch 块内崩溃,这些块具有将结果记录到 redis 和 azure 存储的 finally。这些都不会发生。我无法弄清楚或想象,这个过程是如何在没有遇到任何异常处理程序的情况下崩溃的......?

有人对天蓝色的网络作业有这个问题吗?知道我应该寻找什么或调试这个的任何提示吗?

谢谢!

4

1 回答 1

4

I figured it out! One of the many things happening asynchronously was the creation of a certificate. I traced it down to this:

signedCert = new X509Certificate2(cert, "notasecret", X509KeyStorageFlags.Exportable);

This code works fine when called from my azure website or my tests, but kills the webjob process completely without throwing an exception! For example, the WriteLine in the exception handler below never gets called:

X509Certificate2 signedCert;
try
{
    signedCert = new X509Certificate2(cert, "notasecret", X509KeyStorageFlags.Exportable);
}
catch (Exception ex)
{
    // We never get here! Argh!
    Console.WriteLine("Exception converting cert: " + ex);                
    throw;
}

Extremely time consuming and frustrating. Unlike the diagnosis, the fix is simple:

signedCert = new X509Certificate2(
    cert, 
    "notasecret", 
    X509KeyStorageFlags.Exportable | 
    X509KeyStorageFlags.MachineKeySet |
    X509KeyStorageFlags.PersistKeySet);
于 2014-12-16T00:57:47.387 回答