WCF分布式開發常見錯誤解決(4):The type or namespace name 'DataContract' could not be found DataContract找不到
我們進行WCF項目開發,自己定義數據契約的時候會出現這樣的錯誤:
DataContract、DataMember、DataMemberAttribute找不到,如圖:
The type or namespace name 'DataContract' could not be found (are you missing a using directive or an assembly reference?) E:\CodesVs2008\WCFServiceIISHostFrankXuLei\WcfServiceLib\WcfServiceLib\IService1.cs 24 6 WcfServiceLib
The type or namespace name 'DataMember' could not be found (are you missing a using directive or an assembly reference?) E:\CodesVs2008\WCFServiceIISHostFrankXuLei\WcfServiceLib\WcfServiceLib\IService1.cs 30 10 WcfServiceLib
The type or namespace name 'DataMemberAttribute' could not be found (are you missing a using directive or an assembly reference?) E:\CodesVs2008\WCFServiceIISHostFrankXuLei\WcfServiceLib\WcfServiceLib\IService1.cs 30 10 WcfServiceLib
解決辦法,在項目裡添加System.Runtime.Serialization程序集的引用。
生命引用程序集:
using System.Runtime.Serialization;
編譯即可成功。