Vitor Linares Vitor Linares - 2 months ago 25
C# Question

Azure MobileApp Controller returns 500 only if return type is IQueryable

My azure mobile app backend is presenting a strange behavior.
If my controller action returns an

and the entity type has a navigation property, it returns 500.

A simple example:


public class ProductHierarchy : EntityData
public string Name { get; set; }

public string Description { get; set; }

public DateTime ValidFrom { get; set; }

public DateTime ValidTo { get; set; }

public string BrandId{ get; set; }
public virtual Brand Brand { get; set; }

public ProductStatus Status { get; set; }

public int CreatedBy { get; set; }

public int ModifiedBy { get; set; }

Controller Action

public IQueryable<ProductHierarchy> FromBrand(int brandId)
var hierarchies = Query().Where(hi => hi.Brand.OldBrandId ==brandId);
return hierarchies;

When I make a request to this action, with the solution running on my local machine, everything works fine, however when I publish the solution to azure, the
action starts to return 500, with the generic message

"An error has occurred."

In addition, Azure Logs shows me the following exception when I make a request to the action:

Detailed Error Information: Module
__DynamicModule_Microsoft.Owin.Host.SystemWeb.OwinHttpModule,Microsoft.Owin.Host .SystemWeb, Version=, Culture=neutral,PublicKeyToken=31bf3856ad364e35_19e9f0a3-023d-4d8b-83ef- 180a415e7921 Notification PreExecuteRequestHandler Handler ExtensionlessUrlHandler-Integrated-4.0 Error Code 0x00000000

I've found two changes that can avoid the error:

1) When I decorate the
property of the Model with
, the
property is ignored and everything works fine

2) When I change the action return type to
, keeping the
property of the model without the
atribute, everything works fine too.

It leads me to conclude that the problem is happening serializing
have a property with another entity as type.

I didn't found anyone having the same issue, so I started to look into my nuget packages looking for wich package Works or Interact with the serialization proccess, and my suspicious are all over Newtonsoft Json and AutoMapper.

Anyone have some clue about how to look under the hood of these packages and determine the origin of the problem?


There are lots of issues and edge cases around relationships. I'm not surprised you have bumped into an issue.

Some resources:

  1. The book - (particularly chapter 3)
  2. Blog on relationships: