C# 由于未处理的异常,进程已终止
在我的windows服务的代码中,我有一个try-catch块。 当我在数据库上的开发机器上运行单元测试时,单元测试通过了 当服务在具有相同数据库的生产服务器上运行时,会发生错误,Windows事件日志中会出现两个事件C# 由于未处理的异常,进程已终止,c#,multithreading,error-handling,entity-framework-6,C#,Multithreading,Error Handling,Entity Framework 6,在我的windows服务的代码中,我有一个try-catch块。 当我在数据库上的开发机器上运行单元测试时,单元测试通过了 当服务在具有相同数据库的生产服务器上运行时,会发生错误,Windows事件日志中会出现两个事件 EventType clr20r3, P1 MKG.XPREFLIGHT.servicehost.exe, P2 2.0.62.0, P3 574a1457, P4 mscorlib, P5 4.0.0.0, P6 53b50a71, P7 3e5, P8 10d, P9 s
EventType clr20r3, P1 MKG.XPREFLIGHT.servicehost.exe, P2 2.0.62.0,
P3 574a1457, P4 mscorlib, P5 4.0.0.0, P6 53b50a71, P7 3e5, P8 10d,
P9 system.formatexception, P10 NIL.
及
我隔离了发生错误的代码区域,但是由于单元测试通过,我看不出为什么会发生错误
该错误是可重复的,尽管在服务器重新启动后进程第一次运行时故障不会发生在同一位置
代码位于Try-Catch块中,但不会被捕获。相反,服务会在windows事件日志中出现错误时停止
如何对此进行故障排除?[更新] 失败的代码是
public Job GetDeepJobWithUploadInfo(int jobId)
{
// if I throw an error here it is caught
Job job = null;
using (var connect = MakeConnect())
{
job =
connect.job.AsNoTracking()
.Include(
j =>
j.VivUpload.Select(
u =>
u.VivSplitUpload.Select(
s =>
s.VivSplitProfile.Select(
p => p.VivSplitLog.Select(l => l.VivSplitLogType)))))
.Include(j => j.VivUpload.Select(u => u.VivSplitUpload.Select(s => s.VivSplitProfile)))
.Include(j => j.JobTag)
.SingleOrDefault(j => j.JobID == jobId);
}
// never gets to here in production, but does get here in unit test
return job;
}
我已尝试在edmx上运行自定义工具以重新生成实体框架类。尝试显示代码可能会有所帮助,你不这样认为吗?问题是由我的错误处理程序中的错误引起的。问题似乎发生在GetDeepJobWithUploadInfo中,因为它在单独的线程上运行。您可以添加处理程序并显示有关异常的更多详细信息。对于类型,您可以查看InnerException以了解更多详细信息。
public Job GetDeepJobWithUploadInfo(int jobId)
{
// if I throw an error here it is caught
Job job = null;
using (var connect = MakeConnect())
{
job =
connect.job.AsNoTracking()
.Include(
j =>
j.VivUpload.Select(
u =>
u.VivSplitUpload.Select(
s =>
s.VivSplitProfile.Select(
p => p.VivSplitLog.Select(l => l.VivSplitLogType)))))
.Include(j => j.VivUpload.Select(u => u.VivSplitUpload.Select(s => s.VivSplitProfile)))
.Include(j => j.JobTag)
.SingleOrDefault(j => j.JobID == jobId);
}
// never gets to here in production, but does get here in unit test
return job;
}