I am trying to port a mobile service app to a web application. To do so I created a new web application and copied the relevant code from the working mobile service to the new web application that I created (using the mobile app template.
I have the following code in my Startup method in the new application:
public partial class Startup
{
public static void ConfigureMobileApp(IAppBuilder app)
{
HttpConfiguration config = new HttpConfiguration();
new MobileAppConfiguration()
.UseDefaultConfiguration()
.ApplyTo(config);
// Use Entity Framework Code First to create database tables based on your DbContext
Database.SetInitializer(new MobileServiceInitializer());
config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize;
config.Formatters.JsonFormatter.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects;
app.UseWebApi(config);
MobileAppSettingsDictionary settings = config.GetMobileAppSettingsProvider().GetMobileAppSettings();
}
}
The config.Formatters were copied from the original application which returns the entity and its children to the json output of the api controller.
In the new application I had to add the [MobileAppController] to my api controllers. I get the following error from the controller in the web application app: Self referencing loop detected for property Teams (The model has Teams --> Players and players has a teamid)
Based on this detailed question: Self referencing loop detected - Getting back data from WebApi to the browser
The above code should work as it does in my mobile service app. The web service app appears to ignore the config.Formatters value as I have tried every value in the above question but I still get the same error.
If I place the [JSON Ignore] attribute before the Child list, then I do not get the error, but also do not get the children back in the json. How can I get this web application to accept the formatting values?