We have an existing WCF service hosted in a Windows service. The service has been built and deployed targeting .NET Framework 4.0.
A couple of days ago, we installed .NET Framework 4.6.1. The server previously had .NET Framework 4.0.
We are now seeing an exception generated from the service. I've included the exception details below as well as the code for the FillProcessorNetTcpBinding class.
It seems that the .NET upgrade has updated some of the assemblies in a way that is not backwards compatible with .NET 4.0. Our goal is to have the pre-deployed service function as it did before without needing to target .NET 4.6.1.
Why are .NET 4.5+ assemblies being used when the application is targeting .NET 4.0?
Any suggestions?
<TypeLoadException xmlns="http://schemas.datacontract.org/2004/07/System">
<Message>
Could not load type 'System.Net.WebSockets.WebSocket' from assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
</Message>
<Source>
System.ServiceModel
</Source>
<TargetSite>
Boolean get_IsApplicationTargeting45()
</TargetSite>
<StackTrace>
at System.ServiceModel.OSEnvironmentHelper.get_IsApplicationTargeting45()
at System.ServiceModel.Channels.ConnectionOrientedTransportBindingElement..ctor()
at System.ServiceModel.NetTcpBinding.Initialize()
at System.ServiceModel.NetTcpBinding..ctor()
at Company.Shared.Processor.Access.WCF.ProcessorNetTcpBinding..ctor() in c:\TeamCity\BuildAgent\work\11b9dc3c2c069bfb\Release \Main\Shared\Processor\Access\WCF\ProcessorNetTcpBinding.cs:line 12
at Company.Shared.Processor.Access.WCF.Client.ProcessorServiceClient.CreateTcpEndPoint(String hostName, UInt16 portNumber) in c:\TeamCity\BuildAgent\work\11b9dc3c2c069bfb\Release\Main\Shared\Processor\Access\WCF \ProcessorServiceClient.cs:line 34
at Company.shared.Processor.Listener.ListenerManager.CallProcessor(Object msg) in c:\TeamCity\BuildAgent\work\11b9dc3c2c069bfb\Release\Main\Shared\Processor\Listener\Service\ListenerManager.cs:line 212
</StackTrace>
</TypeLoadException>
Referenced class that extends NetTcpBinding
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Security;
using System.ServiceModel;
using System.Text;
namespace Company.Shared.Processor.Access.WCF
{
public class ProcessorNetTcpBinding : NetTcpBinding
{
public ProcessorNetTcpBinding()
{
MaxBufferSize = Int32.MaxValue;
MaxReceivedMessageSize = MaxBufferSize;
ReaderQuotas.MaxStringContentLength = Int32.MaxValue;
ReaderQuotas.MaxArrayLength = Int32.MaxValue;
ReaderQuotas.MaxBytesPerRead = 65536;
ReaderQuotas.MaxDepth = 64;
SendTimeout = TimeSpan.FromMinutes(5);
Security.Mode = SecurityMode.Transport;
Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows;
Security.Transport.ProtectionLevel = ProtectionLevel.Sign;
}
}
}
App.config
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="CompanyWcf" type="Company.Shared.Utils.Wcf.Config.WcfConfigSection, Company.Shared.Utils"/>
</configSections>
<appSettings>
<add key="Company.Shared.Alerting" value="http://Alerting.company.com/api/"/>
</appSettings>
<connectionStrings>
<add name="AlertingDb" connectionString="Data Source=SQLSERVER;Initial Catalog=Company;Integrated Security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
<add name="OracleConnection" connectionString="Data Source=ODEP;User ID=/;Pooling=false;Connection Timeout=260;" providerName="System.Data.OracleClient" />
<add name="ThorConnection" connectionString="Data Source=SQLSERVER;Initial Catalog=Thor;Integrated Security=True"/>
</connectionStrings>
<!-- Company WCF-->
<CompanyWcf>
<Services>
<add name="Company Processor" host="localhost" port="4329" />
<add name="Company Processor Listener" host="localhost" port="4330" />
</Services>
</CompanyWcf>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
.net 4.0 vs .net 4.6.x
– MethodManusing System.Net.WebSockets.WebSocket
but you will need to manually add the reference to the project's references node as well – MethodMan