昨天在開發時遇到一個很簡單但是很奇怪的問題
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