title: JsonSerializationException on lazy loaded nHibernate object in WebApi when called from Angularjs service
body: <p>I am calling a WebApi controller Get method from an Angularjs service.</p>
  
  <p>The angular service:</p>
  
  <pre><code>app.service('MyService', ['$http', function ($http) {
  
      var getMyObjects = function () {
          var myObjects;
          var promise = $http.get('/api/objects/').success(function (data) {
              myObjects = data;
           }).error(function (data, status, headers, config) {
  
           });
  
           return promise;
      };
  
      return {
          myObjects: myObjects
      };
  }]);
  </code></pre>
  
  <p>The WebApi Get method:</p>
  
  <pre><code>public class ObjectsController : ApiController
  {
      public IEnumerable&lt;MyObject&gt; Get()
      {
          return _objectRepository.GetAll().ToArray();
      }
  }
  </code></pre>
  
  <p>I am getting a <code>500 server error</code> on the client, the inner exception of which is:</p>
  
  <pre><code>ExceptionMessage: "Error getting value from 'IdentityEqualityComparer' on 
  'NHibernate.Proxy.DefaultLazyInitializer'."
  ExceptionType: "Newtonsoft.Json.JsonSerializationException"
  </code></pre>
  
  <p>What should I do to resolve this issue? </p>
  
  <p><strong>EDIT:</strong> 
  I resolved the above exception by adding the following one liner to <code>WebApiConfig.cs</code> as per <a href="https://stackoverflow.com/a/13278092/1005609">this answer</a>:</p>
  
  <pre><code>((DefaultContractResolver)config.Formatters.JsonFormatter.SerializerSettings.
                             ContractResolver).IgnoreSerializableAttribute = true;
  </code></pre>
  
  <p>Now I have this exception:</p>
  
  <pre><code>ExceptionMessage: "Error getting value from 'DefaultValue'
  on 'NHibernate.Type.DateTimeOffsetType'."
  ExceptionType: "Newtonsoft.Json.JsonSerializationException"
  </code></pre>
  
  <p>Any ideas on if there is something similar I can do to fix this?</p>