I am calling a WebApi controller Get method from an Angularjs service.
The angular service:
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
};
}]);
The WebApi Get method:
public class ObjectsController : ApiController
{
public IEnumerable<MyObject> Get()
{
return _objectRepository.GetAll().ToArray();
}
}
I am getting a 500 server error
on the client, the inner exception of which is:
ExceptionMessage: "Error getting value from 'IdentityEqualityComparer' on
'NHibernate.Proxy.DefaultLazyInitializer'."
ExceptionType: "Newtonsoft.Json.JsonSerializationException"
What should I do to resolve this issue?
EDIT:
I resolved the above exception by adding the following one liner to WebApiConfig.cs
as per this answer:
((DefaultContractResolver)config.Formatters.JsonFormatter.SerializerSettings.
ContractResolver).IgnoreSerializableAttribute = true;
Now I have this exception:
ExceptionMessage: "Error getting value from 'DefaultValue'
on 'NHibernate.Type.DateTimeOffsetType'."
ExceptionType: "Newtonsoft.Json.JsonSerializationException"
Any ideas on if there is something similar I can do to fix this?