Wednesday, December 3, 2014

Upgrading a 2008R2 to 2012R2 might cause issues for WCF self-hosted service

The following error occurs after upgrading a Windows 2008R2 server to Windows 2012R2:

System.TypeLoadException: Could not load type 'System.Runtime.Diagnostics.ITraceSourceStringProvider' from assembly 'System.ServiceModel.Internals, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
   at System.ServiceModel.Channels.BinaryMessageEncoderFactory..ctor(MessageVersion messageVersion, Int32 maxReadPoolSize, Int32 maxWritePoolSize, Int32 maxSessionSize, XmlDictionaryReaderQuotas readerQuotas, Int64 maxReceivedMessageSize, BinaryVersion version, CompressionFormat compressionFormat)
   at System.ServiceModel.Channels.BinaryMessageEncodingBindingElement.CreateMessageEncoderFactory()
   at System.ServiceModel.Channels.TransportChannelFactory`1..ctor(TransportBindingElement bindingElement, BindingContext context)
   at System.ServiceModel.Channels.ConnectionOrientedTransportChannelFactory`1..ctor(ConnectionOrientedTransportBindingElement bindingElement, BindingContext context, String connectionPoolGroupName, TimeSpan idleTimeout, Int32 maxOutboundConnectionsPerEndpoint, Boolean supportsImpersonationDuringAsyncOpen)
   at System.ServiceModel.Channels.TcpTransportBindingElement.BuildChannelFactory[TChannel](BindingContext context)
   at System.ServiceModel.Channels.Binding.BuildChannelFactory[TChannel](BindingParameterCollection parameters)
   at System.ServiceModel.Channels.ServiceChannelFactory.BuildChannelFactory(ServiceEndpoint serviceEndpoint, Boolean useActiveAutoClose)
   at System.ServiceModel.ChannelFactory.CreateFactory()
   at System.ServiceModel.ChannelFactory.OnOpening()
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.ChannelFactory.EnsureOpened()
   at System.ServiceModel.DuplexChannelFactory`1.CreateChannel(InstanceContext callbackInstance, EndpointAddress address, Uri via)
   at ChangeAuditor.AgentServiceProxy.CAgentServiceProxy.Open(String ConnName, String ServiceUri, Boolean IsWorkstation, String SpnName, String ForeignDomain, String ForeignUserName, String ForeignPassword)


This is happening only if you upgrading a 2008(R2) server that had .Net Framework 4.5.2 installed prior to the upgrade. After upgrading to 2012, you only see .Net Framework 4.5.1 installed:











If you look at the version of the dlls on the upgraded machine, you see the following:
System.ServiceModel.dll - 4.0.30319.34209
System.ServiceModel.Internals.dll - 4.0.30319.33440

The System.ServiceModel.dll references ITraceSourceStringProvider:













Which does not exist in the System.ServiceModel.Internals.dll after the upgrade:

To solve the issue, .Net Framework should be installed again on the upgraded 2012 server.

When you install 4.5.2 you see both files show 4.0.30319.34209 version and System.ServiceModel.Internals.dll has ITraceSourceStringProvider: