title: Serialization of MS CRM 2011 plugin execution context to JSON
body: <p>I'm trying to serialize MS CRM 2011 plugin execution context to JSON to analyze it later (I need to find issue of the error, and I would prefer to have more human-readable form of context dump).</p>
  
  <p>But all my tries leads to a serialization errors, like following:</p>
  
  <p><code>Newtonsoft.Json.JsonSerializationException: Error getting value from 'ServiceProvider' on 'Plugin+LocalPluginContext</code></p>
  
  <p>Plugin was generated by Visual Studio add-on. Code was placed inside base class <code>Plugin</code>, like this:</p>
  
  <pre><code>internal void Trace(string message)
  {
      if (string.IsNullOrWhiteSpace(message) || this.TracingService == null)
      {
          return;
      }
  
      if (this.PluginExecutionContext == null)
      {
          this.TracingService.Trace(message);
      }
      else
      {
          this.TracingService.Trace(
              "{0}, Correlation Id: {1}, Initiating User: {2}",
              message,
              this.PluginExecutionContext.CorrelationId,
              this.PluginExecutionContext.InitiatingUserId);
  
          var jss = new JsonSerializerSettings();
          var dcr = new DefaultContractResolver();
  
          dcr.DefaultMembersSearchFlags |= System.Reflection.BindingFlags.NonPublic;
          jss.ContractResolver = dcr;
  
          this.TracingService.Trace("Local Context Dump: {0}", JsonConvert.SerializeObject(this, jss));
      }
  }
  </code></pre>
  
  <p>I believe the issue is the general approach. <code>LocalContext</code> is very complex object. JSON.NET is unable to serialize some kind of types. But I cannot nail down this restriction.</p>
  
  <p>Could you please help me to correct the approach?</p>