Glimpse 中 Json.NET 序列化的问题

发布于 2024-12-21 10:20:19 字数 4513 浏览 2 评论 0 原文

我一直在跨平台原型上测试 Glimpse,该原型将 MVVM 用于各种前端(MVC3、WPF4、WP7),并且由于 Json.NET 序列化问题,似乎在 MVC3 中遇到了 Glimpse 问题。对于不使用 MVVM 的视图,Glimpse 工作正常。

使用 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,我尝试使用 [JsonIgnore] 或 <来标记关联的模型/视图模型字段 [NonSerialized] 和属性code>[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状态属性中的Token PropertyName将导致无效的JavaScript对象,并且似乎其他人也是如此。

有谁知道代币X状态X指的是什么?

I've been testing out Glimpse on a cross-platform prototype which uses MVVM for various front ends (MVC3, WPF4, WP7) and appear to have run into issues with Glimpse in MVC3 due to Json.NET serialization woes. Glimpse is working fine for views not using MVVM.

Using MVVMLight v3.0.3, Autofac for DI v2.5.2 and Glimpse v0.86.

Here's the Glimpse log:

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

For the NotSupportedException I tried marking the associated model/view model fields [NonSerialized] and properties with [JsonIgnore] or [ScriptIgnore] to no avail, as CommandConverter appears to be the sticking point, since RelayCommand implements 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

Anyone know how to get around that?

Also, I'm at a loss to explain the JsonWriterException: Token PropertyName in state Property would result in an invalid JavaScript object, and it seems other people are too.

Does anyone know what token X and state X refer to?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

饮惑 2024-12-28 10:20:19

这是一个已知问题 - 我很惊讶 JsonIgnore 没有工作,因为它应该工作......

更一般地说,自从引入视图模型的序列化以来,我们在做你“不应该”做的事情时遇到了问题正在做。最大的例子是人们使用 EF/NH 模型作为他们的 VM,我们运行的序列化过程会触发整个数据库的递归延迟加载。

我们意识到让人们更改代码来工作并不是一个好方法,因此我们将默认关闭序列化过程。

不幸的是,这还没有到位,所以我不能为您提供太多,但请知道我们正在解决这个问题,我们很快就会修复。

更新:

我只是有一个想法。 Glimpse 支持黑名单插件 - http://getglimpse.com/Help/Configuration。这意味着您可以阻止视图插件运行并导致问题。如果您仍然希望视图插件正常工作,您可以做一些更黑客的事情,即在第 73 行将“model”设置为 null - https://github.com/Glimpse/Glimpse/blob/master/source/Glimpse.MVC3/Plugin/Views.cs

我再次知道这两者都不理想,但它可以让你此时此地启动并运行。

This is a known issue - I am surprised that JsonIgnore didn't work as its something that should have worked...

More generally, since introducing the serialization of view models we have had problem with problem doing what you "shouldn't" be doing. The biggest example of this is people using EF/NH models as their VM and the serialization process we run triggers the recursive lazy loading of the whole database.

We realize that making people change their code to work isn't a good approach and hence we are going to be turning off the serialization process by default.

Unfortunately this isn't in place yet so their isn't much I can offer you, but know we are onto it and we will have a fix soon.

UPDATE:

I just had a thought. Glimpse supports blacklisting plugins - http://getglimpse.com/Help/Configuration. This means you can stop the Views plugin from running and causing issues. If you still want the view plugin to work, something a bit more hackish you could do is set "model" to null on line 73 - https://github.com/Glimpse/Glimpse/blob/master/source/Glimpse.MVC3/Plugin/Views.cs.

Again I know that neither are ideal, but it gets you up and running here and now.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文