無法找到System.Runtime.Serialization.Json的奇怪問題


昨天在開發時遇到一個很簡單但是很奇怪的問題 

if ((filterContext.HttpContext.Request.ContentType ?? string.Empty).Contains("application/json"))
{
    object o =new DataContractJsonSerializer(RootType).ReadObject(filterContext.HttpContext.Request.InputStream);
    filterContext.ActionParameters[Param] = o;
}

 

DataContractJsonSerializer 無法找到相應的鏈接庫, 添加了System.Runtime.Serialization也無法解決。

解決問題的思路是:

1.認為是自己沒有.net 3.0的版本,檢查了之后發現存在,然后想到可能不是最新的版本,於是上網下載更新,結果依然沒有解決問題。

2.google it and find the answer:

You need to add a reference to the System.ServiceModel assembly as well.

using System.Runtime.Serialization;
using System.ServiceModel;

System.Runtime.Serialization.dll(下載
System.ServiceModel.dll
System.ServiceModel.Web.dll

Hope this helps!

Very Stranger but very happy


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM