0

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

Ionesta
  • 21
  • 1
  • I remember, when FW4.5 beta came out, during installation it warned that 4.0 will be overridden and its features will be lost. I am not sure if this is still the case but I remember that warning. – T.S. Dec 13 '13 at 15:26
  • See if this may help you: http://msdn.microsoft.com/en-us/library/7wd6ex19%28v=vs.110%29.aspx – T.S. Dec 13 '13 at 15:28
  • @T.S. Thanks for the answer, but it's not working. I have used the folowing configuration: – Ionesta Dec 16 '13 at 09:46
  • Probably it's not working because in GAC I have only the system.data.dll from the 4.5 framework – Ionesta Dec 16 '13 at 09:49

0 Answers0