Self hosted WCF net.tcp service app fails to start intermittently

1

We have a windows service that listens on a WCF port. The service starts up and successfully binds to the port maybe 25% of the time. This is happening on 2 different machines. This code has been stable for some time, the only difference may be that we re-targetted to .NET 4.6.2 while back, but we're not completely sure if it had anything to do with this. When it fails we get the following:

System.IO.FileLoadException: Could not load file or assembly 'System.ServiceModel.Internals, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. Provider type not defined. (Exception from HRESULT: 0x80090017)
File name: 'System.ServiceModel.Internals, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
   at System.ServiceModel.Diagnostics.TraceUtility.SetEtwProviderId()
   at System.ServiceModel.ServiceHostBase..ctor()
   at System.ServiceModel.ServiceHost..ctor(Object singletonInstance, Uri[] baseAddresses)
   at PSC.Tools.Communication.ListeningExecutorServerWCF.OnStart()

=== Pre-bind state information ===
LOG: DisplayName = System.ServiceModel.Internals, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
(Fully-specified)
LOG: Appbase = file:///D:/FieldAssist/Server/binaries/Links/
LOG: Initial PrivatePath = NULL
Calling assembly : System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.
===
LOG: This bind starts in default load context.
LOG: No application configuration file found.
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Post-policy reference: System.ServiceModel.Internals, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: Binding succeeds. Returns assembly from C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Internals\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Internals.dll.
LOG: Assembly is loaded in default load context.

As you can see from the binding log info, it does look like it successfully resolved the assembly. Anyone have any ideas?

The line of code throwing the exception is:

ServiceHost serviceHost = new ServiceHost(serviceInstance);

Where serviceInstance is an instance of a class (so that we set up a singleton).

c#
wcf
self-hosting
etw
net.tcp
asked on Stack Overflow Sep 18, 2018 by John Fairbanks

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0