JSON.NET and nHibernate Lazy Loading of Collections

I was facing the same problem so I tried to use @Liedman’s code but the GetSerializableMembers() was never get called for the proxied reference.
I found another method to override:

  public class NHibernateContractResolver : DefaultContractResolver
  {
      protected override JsonContract CreateContract(Type objectType)
      {
          if (typeof(NHibernate.Proxy.INHibernateProxy).IsAssignableFrom(objectType))
              return base.CreateContract(objectType.BaseType);
          else
              return base.CreateContract(objectType);
      }
  }

Leave a Comment