我一直在測試一個跨平臺原型,它使用MVVM的各種前端(MVC3,WPF4,WP7),似乎已經遇到MVC3中的瞥見問題到Json.NET序列化的困境。對於不使用MVVM的視圖,Glimpse工作正常。在瞥見Json.NET序列化的問題
使用MVVMLight v3.0.3,Autofac for DI v2.5.2和Glimpse v0.86。
這裏的一瞥日誌:
2011-12-14 11:23:39.9096|INFO|Glimpse.Core.Module|BeginRequest handling complete for requestId 2e9285ee-a2ac-44fe-bd26-e85fb2f83b1b (/)| 2011-12-14 11:23:39.9096|WARN|Glimpse.Mvc3.Plugin.Execution|get_Binders method of System.Web.Mvc.ControllerActionInvoker type is not proxyable.| 2011-12-14 11:23:39.9096|WARN|Glimpse.Mvc3.Plugin.Execution|set_Binders method of System.Web.Mvc.ControllerActionInvoker type is not proxyable.| 2011-12-14 11:23:39.9096|WARN|Glimpse.Mvc3.Plugin.Execution|GetType method of System.Web.Mvc.ControllerActionInvoker type is not proxyable.| 2011-12-14 11:23:39.9096|WARN|Glimpse.Mvc3.Plugin.Execution|MemberwiseClone method of System.Web.Mvc.ControllerActionInvoker type is not proxyable.| 2011-12-14 11:23:39.9356|INFO|Glimpse.Core.Module|PostRequestHandlerExecute handling complete for requestId 2e9285ee-a2ac-44fe-bd26-e85fb2f83b1b (/)| 2011-12-14 11:23:39.9356|INFO|Glimpse.Core.Module|PostReleaseRequestState handling complete for requestId 2e9285ee-a2ac-44fe-bd26-e85fb2f83b1b (/)| 2011-12-14 11:23:39.9576|WARN|Glimpse.Core.Plumbing.GlimpseSerializer|Serializer error|System.NotSupportedException--'CommandConverter' is unable to convert 'GalaSoft.MvvmLight.Command.RelayCommand' to 'System.String'.-- at System.ComponentModel.TypeConverter.GetConvertToException(Object value, Type destinationType) at System.Windows.Input.CommandConverter.ConvertTo(ITypeDescriptorContext context, CultureInfo culture, Object value, Type destinationType) at System.ComponentModel.TypeConverter.ConvertToString(ITypeDescriptorContext context, CultureInfo culture, Object value) at System.ComponentModel.TypeConverter.ConvertToInvariantString(Object value) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.TryConvertToString(Object value, Type type, String& s) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeString(JsonWriter writer, Object value, JsonStringContract contract) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContract collectionValueContract) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.WriteMemberInfoProperty(JsonWriter writer, Object memberValue, JsonProperty property, JsonContract contract) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContract collectionValueContract) 2011-12-14 11:23:39.9756|WARN|Glimpse.Core.Plumbing.GlimpseSerializer|Serializer error|Newtonsoft.Json.JsonWriterException--Token PropertyName in state Property would result in an invalid JavaScript object.-- at Newtonsoft.Json.JsonWriter.AutoComplete(JsonToken tokenBeingWritten) at Newtonsoft.Json.JsonWriter.WritePropertyName(String name) at Newtonsoft.Json.JsonTextWriter.WritePropertyName(String name) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.WriteMemberInfoProperty(JsonWriter writer, Object memberValue, JsonProperty property, JsonContract contract) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContract collectionValueContract) ... et cetera
對於NotSupportedException
我試圖標記相關聯的模型/視圖模型字段[NonSerialized]
和屬性[JsonIgnore]
或[ScriptIgnore]
無濟於事,因爲CommandConverter
似乎是關鍵的,因爲RelayCommand
實現ICommand
:
[TypeConverter("System.Windows.Input.CommandConverter, PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, Custom=null"), ValueSerializer("System.Windows.Input.CommandValueSerializer, PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, Custom=null")]
public interface ICommand
任何人都知道怎麼去解決呢?
此外,我茫然地解釋JsonWriterException
:令牌屬性名國家財產會導致一個無效的JavaScript對象,似乎other people也有同感。
有沒有人知道什麼令牌X和狀態X是指?
謝謝安東尼!列入黑名單視圖插件讓事情滾動,但我會進一步試驗'JsonIgnore`,看看它是否可以解決問題。 – si618 2011-12-15 23:59:39