WCF Windows Service fails to start, throws System.IO.FileNotFoundException

I’ve been battling an issue for several days. Among our solutions, we have an aging monolith comprising various ASP.NET technologies, as well as a WCF service, and several other Windows Services. Everything builds for my colleagues, and the services all start correctly. I hadn’t worked on the monolith in a while, and when I turned my attention back to it, I experienced some various errors, including one that I still have not solved. In order for our WCF stuff to work, we have to run a Windows Service that acts as the WCF host. When I try to start this service, it bombs out, throwing up this dialog:

Windows could not start the {name of service} service on Local Computer. Error 1064: An exception occurred in the service when handling the control request.

Checking Event Viewer, I find this .NET Runtime error in Windows Logs/Application:

Application: {redacted full path/name of WCF service host}.exe Framework Version: v4.0.30319 Description: The process was terminated due to an unhandled exception. Exception Info: System.IO.FileNotFoundException  Exception Info: System.IO.FileNotFoundException    at System.ServiceModel.Channels.HttpChannelListener..ctor(System.ServiceModel.Channels.HttpTransportBindingElement, System.ServiceModel.Channels.BindingContext)    at System.ServiceModel.Channels.HttpChannelListener`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]..ctor(System.ServiceModel.Channels.HttpTransportBindingElement, System.ServiceModel.Channels.BindingContext)    at System.ServiceModel.Channels.HttpTransportBindingElement.BuildChannelListener[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.ServiceModel.Channels.BindingContext)    at System.ServiceModel.Channels.Binding.BuildChannelListener[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.Uri, System.String, System.ServiceModel.Description.ListenUriMode, System.ServiceModel.Channels.BindingParameterCollection)    at System.ServiceModel.Description.ServiceMetadataExtension.CreateGetDispatcher(System.Uri, System.ServiceModel.Channels.Binding, System.String)    at System.ServiceModel.Description.ServiceMetadataExtension.EnsureGetDispatcher(System.Uri, Boolean)    at System.ServiceModel.Description.ServiceMetadataBehavior.EnsureGetDispatcher(System.ServiceModel.ServiceHostBase, System.ServiceModel.Description.ServiceMetadataExtension, System.Uri, System.String)    at System.ServiceModel.Description.ServiceMetadataBehavior.CreateHttpGetEndpoints(System.ServiceModel.Description.ServiceDescription, System.ServiceModel.ServiceHostBase, System.ServiceModel.Description.ServiceMetadataExtension)    at System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(System.ServiceModel.Description.ServiceDescription, System.ServiceModel.ServiceHostBase)    at System.ServiceModel.ServiceHostBase.InitializeRuntime()    at System.ServiceModel.ServiceHostBase.OnOpen(System.TimeSpan)    at System.ServiceModel.Channels.CommunicationObject.Open(System.TimeSpan)    at {elided - a few more stack trace lines referring to our custom code} 

Also in the same Event Viewer log, I have this Application Error (immediately after the .NET Runtime one):

Faulting application name: {service name}.exe, version: 4.2.0.0, time stamp: 0x5f0f45ce Faulting module name: KERNELBASE.dll, version: 10.0.18362.815, time stamp: 0xb89efff3 Exception code: 0xe0434352 Fault offset: 0x000000000003a799 Faulting process id: 0xd84 Faulting application start time: 0x01d65ad32192a62b Faulting application path: {full service path/name}.exe Faulting module path: C:\WINDOWS\System32\KERNELBASE.dll Report Id: 1db8e59a-b3a0-47e3-bb0f-5d8c6e2f8ed5 Faulting package full name:  Faulting package-relative application ID:  

I’ve mostly been working in .NET Core with VS 2019 for the past year and a half, and so I thought maybe some configuration or SDK needed for Framework had gone missing. I still have 2017 on my machine, and that is what my colleagues prefer to use for this one monolithic solution. Now, over these several days, I have done the following:

  • Removed and/or installed various SDKs and targeting packs
  • Repaired VS 2017
  • Uninstalled and reinstalled VS 2017
  • Repaired VS 2019
  • Uninstalled and reinstalled VS 2019
  • Uninstalled and reinstalled the Windows Services many times

I’ve picked up the vaguest hints from web search results above my head that there could be a problem with some binding redirects. Initially I could have sworn I saw evidence that the FileNotFound was something in System.Net.Http, but now I can’t seem to find whatever indicated that to me. At this point I’m completely burnt on it, and I’m considering just wiping the whole system and starting with a clean Windows installation. It would be a real shame if I were to have to do that. If you have even the vaguest hint about where to look or what to try, it would be much appreciated.

Add Comment
1 Answer(s)

This may be due to the failure to find the WCF configuration file when the service starts, which can not start normally.

enter image description here

You need to check the value of the service name, the service name is not set randomly, this is the implementation class of the service interface.

enter image description here

The above picture is the interface and implementation class of WCF service.

For more details about hosting WCF in windows service, please refer to the link below:

https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-host-a-wcf-service-in-a-managed-windows-service

Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.