2

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?

Community
  • 1
  • 1
si618
  • 16,580
  • 12
  • 67
  • 84

1 Answers1

2

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.

anthonyv
  • 2,455
  • 1
  • 14
  • 18
  • Thanks Anthony! Blacklisting the Views plugin got things rolling, but I will experiment further with `JsonIgnore` to see if it can solve the problem. – si618 Dec 15 '11 at 23:59