title: Newtonsoft.Json.JsonSerializationException "Self referencing loop detected" in library code
body: <p>I have self referencing data: each Item contains a list of Scrapbooks that it is a member of and each Scrapbook contains a list of Items it contains. Clearly that's circular, and so when a Scrapbook is serialised I get a Newtonsoft.Json.JsonSerializationException "Self referencing loop detected" error. We get around this on our Azure Mobile Services server by adding the line</p>
  
  <pre class="lang-cs prettyprint-override"><code>GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize;
  </code></pre>
  
  <p>in the <code>App_Start()</code> method of the <code>Global.asax.cs</code> file. But in the phone client I get the exception at this line of code:</p>
  
  <pre class="lang-cs prettyprint-override"><code>await _ScrapbookTable.UpdateAsync(liveScrapbook); 
  </code></pre>
  
  <p>where _ScrapbookTable is of type <code>Microsoft.WindowsAzure.Services.MobileServices.IMobileServiceTable&lt;Scrapbook&gt;</code>.</p>
  
  <p><a href="http://www.newtonsoft.com/json/help/html/ReferenceLoopHandlingIgnore.htm" rel="nofollow noreferrer">The documentation</a> (and <a href="https://stackoverflow.com/a/13549982/575530">other answers here</a>) show how to fix this:</p>
  
  <pre class="lang-cs prettyprint-override"><code>var json = JsonConvert.SerializeObject(joe, Formatting.Indented, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore });
  </code></pre>
  
  <p>But this fix assumes that it is my code doing the serializing, rather than it being inside a call to an API function (in my case <a href="https://msdn.microsoft.com/en-us/library/jj822306.aspx" rel="nofollow noreferrer"><code>Microsoft.WindowsAzure.Services.MobileServices.IMobileServiceTable&lt;Scrapbook&gt;.UpdateAsync</code></a>).</p>
  
  <p>Is there a way I could decorate the Item and Scrapbook classes with Json attributes (e.g. <a href="http://www.newtonsoft.com/json/help/html/JsonObjectAttributeOptIn.htm" rel="nofollow noreferrer"><code>[JsonObject(MemberSerialization.OptIn)]</code></a>) to prevent the exception?</p>