如何强制我的应用程序在已安装4.5 .Net Framework的工作站上使用.net Framework 4.0中的System.Data.dll?

时间:2013-12-13 13:14:55

标签: .net sqlconnection system.data

我有一个通过WCF进行通信的客户端 - 服务器应用程序。我有一个方法,从服务器向客户端发送 System.Data.SqlClient.SqlConnection 。在工作站上安装visual studio 2012(安装了.NetFramework 4.5)之后,当尝试将SqlConnection从服务器发送到客户端时,服务器和客户端之间的通信失败。 因为串行在WCF服务中使用时出现错误,DataContractSerializer的,不能因为在.NET框架4.5有类型的新属性的凭据 SqlCredential 序列SqlConnection对象,其无法序列化。这是错误:

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.

在我的解决方案中,我已将目标框架设置为 .Net Frameowrk 4.0 ,甚至将System.Data.dll从4.0 Framework设置为解决方案的引用强制应用程序使用此应用程序而不是GAC中的应用程序。 在调试模式下执行此操作后,我无法看到Credential属性,因此很明显它使用了System.Data.dll的4.0版本,但是如果我使用反射来检查SqlConnection类型,则SqlConnection对象中存在Credential属性:

var props = typeof(System.Data.SqlClient.SqlConnection).GetProperties();
foreach (var propie in props)
{
 string propName = propie.Name;
}

问题是:如何强制我的应用程序在已安装4.5 .Net Framework的工作站上使用.net Framework 4.0中的System.Data.dll?

谢谢

0 个答案:

没有答案