C# .Net服务失败,新线程启动方法出现FileNotFound异常
我有一个我编写的服务,它执行核心业务逻辑和功能。该服务被设计为一个项目中的服务包装器以及Windows Library项目中的所有功能。我还有控制台applcaton,它也包装了Windows库项目 在我们的预生产环境中,这一切都很好。服务开始了,一切都进行得很顺利 在我们的生产环境中,服务无法启动C# .Net服务失败,新线程启动方法出现FileNotFound异常,c#,.net,multithreading,windows-services,C#,.net,Multithreading,Windows Services,我有一个我编写的服务,它执行核心业务逻辑和功能。该服务被设计为一个项目中的服务包装器以及Windows Library项目中的所有功能。我还有控制台applcaton,它也包装了Windows库项目 在我们的预生产环境中,这一切都很好。服务开始了,一切都进行得很顺利 在我们的生产环境中,服务无法启动 Application: URTWorkerService.exe Framework Version: v4.0.30319 Description: The process was termin
Application: URTWorkerService.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.FileNotFoundException
Stack:
at URTWorker.Worker.Run()
at System.Threading.ThreadHelper.ThreadStart_Context(System.Object)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
at System.Threading.ThreadHelper.ThreadStart()
我觉得这很奇怪,于是添加了一个Debug.WriteLine()调用,如下所示:
/// <summary>
/// Entry point method into the Worker class
/// </summary>
public void Run()
{
Debug.WriteLine("Did we make it this far?");
var exitEventArgs = ExitEventArgs.Clear;
try
{
BroadcastEcho("Worker::Run::Enter", TraceLevel.Verbose);
WorkerStartedOn = DateTime.Now;
State = AsyncState.Running;
BroadcastEcho("Worker::Run::Pre initialize", TraceLevel.Verbose);
Initialize();
BroadcastEcho("Worker::Run::Post initialize", TraceLevel.Verbose);
ExecuteWorkerLoop();
}
catch (Exception ex)
{
exitEventArgs.Reason = ExitReason.Exception;
var vars = new Dictionary<string, string>();
StandardMessage message;
// TODO Comment about this
if (ex is FormatException && ex.Message.Contains("FieldNames.cs"))
{
BroadcastEcho("The field definition has changed. Generating new code file.", ex);
var path = CreateConstantsCodeFile();
BroadcastEcho("The file has been saved to " + path, TraceLevel.Error);
vars.Add("FieldsNamesPath", path);
message = StandardMessage.NewFieldsNameFile;
}
else
{
BroadcastEcho("An unhandled exception was thrown", ex);
vars.Add("ExtraInfo", "<b>This is a crashing exception.</b>");
message = StandardMessage.UnhandledError;
}
Notifier.SendErrorMail(message, vars, ex);
}
var lastCount = -1;
while (Notifier.MailInTransit.Count > 0)
{
if (lastCount != Notifier.MailInTransit.Count)
{
var suffix = (
lastCount != 1
? "s"
: string.Empty);
lastCount = Notifier.MailInTransit.Count;
BroadcastEcho(string.Format("Waiting for {0} mail item{1} to finish sending", lastCount, suffix), TraceLevel.Info);
}
Thread.Sleep(0);
}
State = AsyncState.Stopped;
BroadcastEcho("Worker::Run::Exit", TraceLevel.Verbose);
Exit(exitEventArgs);
}
您可以看到所有的broadcastedecho()
消息,如TraceLevel值所示,但是Debug.WriteLine()
从未出现
然后我认为这可能是程序集绑定的问题。以下是融合日志结果:
*** Assembly Binder Log Entry (1/24/2013 @ 7:47:52 AM) ***
The operation was successful.
Bind result: hr = 0x0. The operation completed successfully.
Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable C:\RTWorker\URTWorkerService.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: User = REDMOND\msrrtsa
LOG: DisplayName = URTWorker, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
(Fully-specified)
LOG: Appbase = file:///C:/RTWorker/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = URTWorkerService.exe
Calling assembly : URTWorkerService, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\RTWorker\URTWorkerService.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/RTWorker/URTWorker.DLL.
LOG: Assembly download was successful. Attempting setup of file: C:\RTWorker\URTWorker.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: URTWorker, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
LOG: Binding succeeds. Returns assembly from C:\RTWorker\URTWorker.dll.
LOG: Assembly is loaded in default load context.
这两台计算机都是Windows Server 2008 R2 SP1。预生产是一台虚拟机,生产是一台物理机
关于它可能是什么的任何建议?在黑暗中拍摄,显式强制刷新()或设置Debug.AutoFlush=true?我发现了问题 首先,我应该查看所有的Fusion日志,而不仅仅是应用于
URTWorker.dll
的日志
*** Assembly Binder Log Entry (1/24/2013 @ 8:53:57 AM) ***
The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.
Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable C:\RTWorker\URTWorkerService.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: User = REDMOND\msrrtsa
LOG: DisplayName = Microsoft.TeamFoundation.WorkItemTracking.Client, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
(Fully-specified)
LOG: Appbase = file:///C:/RTWorker/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = URTWorkerService.exe
Calling assembly : URTWorker, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\RTWorker\URTWorkerService.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Microsoft.TeamFoundation.WorkItemTracking.Client, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/RTWorker/Microsoft.TeamFoundation.WorkItemTracking.Client.DLL.
LOG: Attempting download of new URL file:///C:/RTWorker/Microsoft.TeamFoundation.WorkItemTracking.Client/Microsoft.TeamFoundation.WorkItemTracking.Client.DLL.
LOG: Attempting download of new URL file:///C:/RTWorker/Microsoft.TeamFoundation.WorkItemTracking.Client.EXE.
LOG: Attempting download of new URL file:///C:/RTWorker/Microsoft.TeamFoundation.WorkItemTracking.Client/Microsoft.TeamFoundation.WorkItemTracking.Client.EXE.
LOG: All probing URLs attempted and failed.
失败的绑定指示在没有安装Team Foundation客户机库时无法找到它们,并将引用设置为“代码> CopyStudio=Trime并不能获取所有内容。
这给了我一个更好的方向现在,如果.Net有更好的异常方法(“FileNoteFound:Cannot load assembly XXX.”,那就太好了。检查您在web.config中给出的文件路径,并在Approver中更正
*** Assembly Binder Log Entry (1/24/2013 @ 8:53:57 AM) ***
The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.
Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable C:\RTWorker\URTWorkerService.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: User = REDMOND\msrrtsa
LOG: DisplayName = Microsoft.TeamFoundation.WorkItemTracking.Client, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
(Fully-specified)
LOG: Appbase = file:///C:/RTWorker/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = URTWorkerService.exe
Calling assembly : URTWorker, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\RTWorker\URTWorkerService.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Microsoft.TeamFoundation.WorkItemTracking.Client, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/RTWorker/Microsoft.TeamFoundation.WorkItemTracking.Client.DLL.
LOG: Attempting download of new URL file:///C:/RTWorker/Microsoft.TeamFoundation.WorkItemTracking.Client/Microsoft.TeamFoundation.WorkItemTracking.Client.DLL.
LOG: Attempting download of new URL file:///C:/RTWorker/Microsoft.TeamFoundation.WorkItemTracking.Client.EXE.
LOG: Attempting download of new URL file:///C:/RTWorker/Microsoft.TeamFoundation.WorkItemTracking.Client/Microsoft.TeamFoundation.WorkItemTracking.Client.EXE.
LOG: All probing URLs attempted and failed.