I have a client-server application which communicates through WCF. I have a method that sends a System.Data.SqlClient.SqlConnection from the server to the client. After installing visual studio 2012 (which installed .NetFramework 4.5) on the working stations, the communication between the server and the client fails when trying to send the SqlConnection from the server to the client. The error occurs because the Serializer used in the WCF service, DataContractSerializer, can not serialize the SqlConnection object because in .net framework 4.5 there is a new property Credential of type SqlCredential which can not be serialized. Here is the error:
System.Runtime.Serialization.InvalidDataContractException: Type 'System.Data.SqlClient.SqlCredential' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. If the type is a collection, consider marking it with the CollectionDataContractAttribute. See the Microsoft .NET Framework documentation for other supported types.
In my solution I 've set the Target Framework to .Net Frameowrk 4.0 and even set as reference to the solution a System.Data.dll from 4.0 Framework to force the application to use this one and not the one from GAC. In Debug Mode after doing this I can't see the Credential Property, so it's clear it uses the 4.0 version of the System.Data.dll, but if I use reflection to inspect the SqlConnection type, the Credential property exists in the SqlConnection object:
var props = typeof(System.Data.SqlClient.SqlConnection).GetProperties();
foreach (var propie in props)
{
string propName = propie.Name;
}
The question is: How can I force my application to use System.Data.dll from the .net Framework 4.0 on a working station the has installed 4.5 .Net Framework on it?
Thank You