Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8338861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:43:20+00:00 2026-06-09T04:43:20+00:00

It was working in Beta I have an object of type ChangeSet<T> deriving from

  • 0

It was working in Beta

I have an object of type ChangeSet<T> deriving from ChangeSet that needs some custom deserialization in order for the rest of my web-api to work. It was working in asp.net mvc 4 beta, but in the rc it’s broken, and in a way that I’m finding very hard to debug.

My scenario

The ChangeSet can represent a change of a number of T objects described by an ID-list. I wanted to deserialize into an object-array or dictionary of some sort to describe which properties of the T objects should be changed, but then I had issues deserializing into the correct datatypes. So I introduced the Change property of type T. The new problem then is that not all properties of Change should be persisted. Only the ones that was included in the json. So I let there be a Properties property containing a list of strings.

My Problem

To allow me to populate Properties I need to access the original json, which is why I need a custom MediaTypeFormatter. (The xml-serializer has a SetSerializer(..) but there is no such method for a JsonSerializer. In the below ReadFromStreamAsync I do this, the problem is that it crashes, and I can’t step into the point where it crashes to get an inner exception. All I get is the following json response to my request:

{
    "ExceptionType": "System.InvalidOperationException",
    "Message":       "Method may only be called on a Type for which Type.IsGenericParameter is true.",
    "StackTrace":    "   at System.RuntimeType.get_DeclaringMethod()"
}

If I remove my ChangeSetJsonFormatter the code doesn’t break, but of course i have no Properties.

My questions

  1. What could be the cause of this?
  2. How can I debug this properly? I have Log4Net, but what should I watch? Can I step into the problem somehow?

The code

This is my FormatterConfig:

public class FormatterConfig
{
    public static void RegisterGlobalFormatters(MediaTypeFormatterCollection formatters)
    {
        var jsonSerializerSettings = formatters.JsonFormatter.SerializerSettings;
        jsonSerializerSettings.Converters.Add(new IsoDateTimeConverter());
        jsonSerializerSettings.NullValueHandling = NullValueHandling.Ignore;

        // At index 0 so that it will try this before the default handler.
        formatters.Insert(0, new ChangeSetJsonFormatter(jsonSerializerSettings));

        formatters.Remove(formatters.XmlFormatter);
    }
}

This is my custom media formatter (sorry about the length):

public class ChangeSetJsonFormatter : JsonMediaTypeFormatter
{
    private static readonly Type ChangeSetType = typeof (ChangeSet<Entity>);

    public ChangeSetJsonFormatter(JsonSerializerSettings jsonSerializerSettings)
    {
        SerializerSettings = jsonSerializerSettings;
    }

    public override bool CanReadType(Type type)
    {
        return type.IsGenericType && type.Namespace == ChangeSetType.Namespace && type.Name == ChangeSetType.Name;
    }

    public override bool CanWriteType(Type type)
    {
        return type.IsGenericType && type.Namespace == ChangeSetType.Namespace && type.Name == ChangeSetType.Name;
    }

    public override Task<object> ReadFromStreamAsync(Type type, Stream stream, HttpContentHeaders contentHeaders, IFormatterLogger formatterLogger)
    {
        var task = Task.Factory.StartNew(() =>
        {
            using (var streamReader = new StreamReader(stream))
            {
                var jsonSource = streamReader.ReadToEnd();
                var deserializedObject =
                    JsonConvert.DeserializeObject(jsonSource, type,
                                                SerializerSettings);
                var changeSet = deserializedObject as ChangeSet;
                if (changeSet != null &&
                    (changeSet.Properties == null ||
                    changeSet.Properties.Count == 0))
                {
                    var properties =
                        JObject.Parse(jsonSource)["Change"]
                               .Select(t => ((JProperty) t).Name)
                               .ToList();
                    changeSet.Properties = properties;
                }

                return deserializedObject;
            }
        });

        return task;
    }
}

And these are the ChangeSet classes:

[DataContract]
public abstract class ChangeSet
{
    [DataMember]
    public IList<string> Properties { get; set; }

    [DataMember]
    public IList<int> IdList { get; set; }
}

[DataContract]
public class ChangeSet<T> : ChangeSet where T : Entity
{
    [DataMember]
    public T Change { get; set; }

    public Dictionary<PropertyInfo, object> Changes
    {
        get 
        {
            if (Properties == null || Properties.Count == 0)
                return new Dictionary<PropertyInfo, object>();

            return typeof (T)
                .GetProperties()
                .Where(pi => Properties.Contains(pi.Name))
                .ToDictionary(pi => pi, pi => pi.GetValue(Change, null));
        }
    }
}

Edit: I was able to produce the trace for the service stack, following this documentation. Now if only I was able to get an entry for my exception. Here’s the output from the default listener:

System.Web.Http.Request: ;;http://localhost:50500/MyService/User?_dc=1343396746443
System.Web.Http.Controllers: DefaultHttpControllerSelector;SelectController;Route='controller:User'
System.Web.Http.Controllers: DefaultHttpControllerSelector;SelectController;User
System.Web.Http.Controllers: HttpControllerDescriptor;CreateController;
System.Web.Http.Controllers: DefaultHttpControllerActivator;Create;
System.Web.Http.Controllers: DefaultHttpControllerActivator;Create;MyCompany.Admin.Service.Controllers.UserController
System.Web.Http.Controllers: HttpControllerDescriptor;CreateController;MyCompany.Admin.Service.Controllers.UserController
System.Web.Http.Controllers: UserController;ExecuteAsync;
System.Web.Http.Action: ApiControllerActionSelector;SelectAction;
System.Web.Http.Action: ApiControllerActionSelector;SelectAction;Selected action 'Put(ChangeSet`1 changeSet)'
System.Web.Http.ModelBinding: HttpActionBinding;ExecuteBindingAsync;
System.Web.Http.ModelBinding: FormatterParameterBinding;ExecuteBindingAsync;Binding parameter 'changeSet'
System.Net.Http.Formatting: ChangeSetJsonFormatter;ReadFromStreamAsync;Type='ChangeSet`1', content-type='application/json'
System.Net.Http.Formatting: ChangeSetJsonFormatter;ReadFromStreamAsync;Value read='MyCompany.Admin.Service.Data.ChangeSet`1[MyCompany.Data.Model.User]'
System.Web.Http.ModelBinding: FormatterParameterBinding;ExecuteBindingAsync;
System.Web.Http.ModelBinding: HttpActionBinding;ExecuteBindingAsync;
System.Web.Http.Controllers: UserController;ExecuteAsync;
System.Net.Http.Formatting: DefaultContentNegotiator;Negotiate;Type='HttpError', formatters=[JsonMediaTypeFormatterTracer, JsonMediaTypeFormatterTracer, FormUrlEncodedMediaTypeFormatterTracer, FormUrlEncodedMediaTypeFormatterTracer]
System.Net.Http.Formatting: JsonMediaTypeFormatter;GetPerRequestFormatterInstance;Obtaining formatter of type 'JsonMediaTypeFormatter' for type='HttpError', mediaType='application/json; charset=utf-8'
System.Net.Http.Formatting: JsonMediaTypeFormatter;GetPerRequestFormatterInstance;Will use same 'JsonMediaTypeFormatter' formatter
System.Net.Http.Formatting: DefaultContentNegotiator;Negotiate;Selected formatter='JsonMediaTypeFormatter', content-type='application/json; charset=utf-8'
System.Web.Http.Request: ;;Content-type='application/json; charset=utf-8', content-length=unknown
System.Net.Http.Formatting: JsonMediaTypeFormatter;WriteToStreamAsync;Value='System.Web.Http.HttpError', type='HttpError', content-type='application/json; charset=utf-8'
System.Net.Http.Formatting: JsonMediaTypeFormatter;WriteToStreamAsync;
System.Web.Http.Controllers: UserController;Dispose;
System.Web.Http.Controllers: UserController;Dispose;
The thread '<No Name>' (0x1ea0) has exited with code 0 (0x0).
The thread '<No Name>' (0x1d6c) has exited with code 0 (0x0).
The thread '<No Name>' (0x19b4) has exited with code 0 (0x0).
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T04:43:21+00:00Added an answer on June 9, 2026 at 4:43 am

    I finally figured out what was breaking. The ModelBinder validation breaks on getter using reflection. In that followup question I’m asking why it’s breaking.

    In this question I was after what’s breaking, which I just answered. Thusly I’m closing this question.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on this site: beta.us.lt And I have been playing with firebug
I've been working with Visual Studio 2010 Beta-2 to get some advanced learning on
I'm trying to setup a private beta for a site that I'm working on.
I have a little sample application I was working on trying to get some
I have a Bank Object that has several nested objects/properties/methods as well as wrapping
I am working on a ExtGWT 3.0 (beta) application. I have a simple Java
I have a working private-beta Rails app on mydomain.com. All the routes work. However,
(I'm working in .NET 4.0 beta, C#.) I have an interface, and all classes
I am working on this project: http://www.e-pedkelnes.beta.verskis.lt/ Actually what I have to do is
I have a beta application that I want to show to 100+ people and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.