title: Error sending back JObject using OpenType
body: <p>I implemented OpenType for my Web API <a href="http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/odata-v4/use-open-types-in-odata-v4" rel="nofollow">http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/odata-v4/use-open-types-in-odata-v4</a>. I can send back random values like String, int, array etc for this Property. However, trying to send back a JObject fails with error
  How can I send back JObject?</p>
  
  <pre><code>HTTP/1.1 500 Internal Server Error
  Cache-Control: private
  Content-Type: application/json; odata.metadata=minimal; odata.streaming=true
  Server: Microsoft-IIS/8.0
  OData-Version: 4.0
  X-AspNet-Version: 4.0.30319
  X-SourceFiles: =?UTF-8?B?RDpcQ29uZmlndXJhdGlvblxDb25maWd1cmF0aW9uU3RvcmVcQ29uZmlndXJhdGlvblNlcnZpY2UuQXBpXGFwaVxTZXJ2aWNlcygnRW5jb2RpbmcnKVxDb25maWd1cmF0aW9ucw==?=
  X-Powered-By: ASP.NET
  Date: Tue, 02 Dec 2014 14:56:01 GMT
  Content-Length: 4046
  
  {
    "error":{
      "code":"","message":"An error has occurred.","innererror":{
        "message":"The 'ObjectContent`1' type failed to serialize the response body for content type 'application/json; odata.metadata=minimal; odata.streaming=true'.","type":"System.InvalidOperationException","stacktrace":"","internalexception":{
          "message":"The given model does not contain the type 'Newtonsoft.Json.Linq.JObject'.","type":"System.InvalidOperationException","stacktrace":"   at System.Web.OData.Formatter.Serialization.ODataSerializerContext.GetEdmType(Object instance, Type type)\r\n   at System.Web.OData.Formatter.Serialization.ODataEdmTypeSerializer.AppendDynamicProperties(Object source, IEdmStructuredTypeReference structuredType, ODataSerializerContext writeContext, List`1 declaredProperties)\r\n   at System.Web.OData.Formatter.Serialization.ODataComplexTypeSerializer.CreateODataComplexValue(Object graph, IEdmComplexTypeReference complexType, ODataSerializerContext writeContext)\r\n   at System.Web.OData.Formatter.Serialization.ODataComplexTypeSerializer.CreateODataValue(Object graph, IEdmTypeReference expectedType, ODataSerializerContext writeContext)\r\n   at System.Web.OData.Formatter.Serialization.ODataCollectionSerializer.CreateODataCollectionValue(IEnumerable enumerable, IEdmTypeReference elementType, ODataSerializerContext writeContext)\r\n   at System.Web.OData.Formatter.Serialization.ODataCollectionSerializer.CreateODataValue(Object graph, IEdmTypeReference expectedType, ODataSerializerContext writeContext)\r\n   at System.Web.OData.Formatter.Serialization.ODataEdmTypeSerializer.CreateProperty(Object graph, IEdmTypeReference expectedType, String elementName, ODataSerializerContext writeContext)\r\n   at System.Web.OData.Formatter.Serialization.ODataEntityTypeSerializer.CreateStructuralProperty(IEdmStructuralProperty structuralProperty, EntityInstanceContext entityInstanceContext)\r\n   at System.Web.OData.Formatter.Serialization.ODataEntityTypeSerializer.CreateStructuralPropertyBag(IEnumerable`1 structuralProperties, EntityInstanceContext entityInstanceContext)\r\n   at System.Web.OData.Formatter.Serialization.ODataEntityTypeSerializer.CreateEntry(SelectExpandNode selectExpandNode, EntityInstanceContext entityInstanceContext)\r\n   at System.Web.OData.Formatter.Serialization.ODataEntityTypeSerializer.WriteEntry(Object graph, ODataWriter writer, ODataSerializerContext writeContext)\r\n   at System.Web.OData.Formatter.Serialization.ODataEntityTypeSerializer.WriteObjectInline(Object graph, IEdmTypeReference expectedType, ODataWriter writer, ODataSerializerContext writeContext)\r\n   at System.Web.OData.Formatter.Serialization.ODataFeedSerializer.WriteFeed(IEnumerable enumerable, IEdmTypeReference feedType, ODataWriter writer, ODataSerializerContext writeContext)\r\n   at System.Web.OData.Formatter.Serialization.ODataFeedSerializer.WriteObjectInline(Object graph, IEdmTypeReference expectedType, ODataWriter writer, ODataSerializerContext writeContext)\r\n   at System.Web.OData.Formatter.Serialization.ODataFeedSerializer.WriteObject(Object graph, Type type, ODataMessageWriter messageWriter, ODataSerializerContext writeContext)\r\n   at System.Web.OData.Formatter.ODataMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, HttpContent content, HttpContentHeaders contentHeaders)\r\n   at System.Web.OData.Formatter.ODataMediaTypeFormatter.WriteToStreamAsync(Type type, Object value, Stream writeStream, HttpContent content, TransportContext transportContext, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()\r\n   at System.Web.Http.WebHost.HttpControllerHandler.&lt;WriteBufferedResponseContentAsync&gt;d__1b.MoveNext()"
        }
      }
    }
  }
  </code></pre>
  
  <p>Here are some details that may help</p>
  
  <p>Class Definitions</p>
  
  <pre><code>public sealed class Configuration
  {
      public string ID { get; set; }
      public ConfigurationValue[] Values
      {
          get;
          set;
      }
  }
  
  public sealed class ConfigurationValue
  {
      public IDictionary&lt;string, object&gt; ScopedValue { get; set; }
  }
  </code></pre>
  
  <p>In the controller, if I create an object as follows, it works</p>
  
  <pre><code>var config = new Configuration{ ID="1", Values = new [] { new ConfigurationValue { ScopedValue = new Dictionary&lt;string, object&gt; {{"Val","1"}}}}};
  </code></pre>
  
  <p>However, if I do the following it blows up</p>
  
  <pre><code>var value=JsonConvert.DeserializeObject(@"{'RetryInterval': 60,'MaxRetryCount': 100}");
  var config = new Configuration{ ID="1", Values = new [] { new ConfigurationValue { ScopedValue = new Dictionary&lt;string, object&gt; {{"Val",value}}}}};
  </code></pre>