Problem Caching Collection Type

We currently have a caching implementation for our service methods that caches the response object. Everything is working as intended except for when the response object contains a property of the type collection (List, IEnumerable, etc.) and we receive the following unserialized output (participants property):

{
    "DateStart": "2016-10-03T00:00:00.0000000-07:00",
    "DateStarted": null,
    "DateEnd": null,
    "DateEnded": null,
    "ProjectId": null,
    "Creator": {
      "UserId": 1,
      "FirstName": "Test",
      "MiddleName": null,
      "LastName": "Name",
      "Picture": null,
      "Initials": "TN"
    },
    "Participants": "[{__type:Namespace.RedactedResponse, Namespace.Redacted,UserId:1,FirstName:Sample,MiddleName:null,LastName:User,Picture:null,Initials:SU,IsAdministrator:True}]"
}

No matter what we do, we’re unable to solve this issue. Here’s our current caching implementation:

public virtual object TryGetCache<T>(Module module, object cacheKey, TimeSpan? expiration, Func<T> factory)
     where T : class
 {
     if (cacheKey == null)
         cacheKey = new Guid();

     var compositeKey = string.Concat(module, ":", cacheKey.ToString());

     if (expiration == null)
         expiration = new TimeSpan(0, 12, 0, 0);

     var cacheResult = Cache.Get<T>(compositeKey);
     if (cacheResult != null)
         return cacheResult;

     var result = factory();
     if (result == null)
         return null;

     Cache.Set(compositeKey, result, expiration);

     return result;
 }

In our AppHost, we have the following properties set for JsConfig:

JsConfig.EmitCamelCaseNames = false;
JsConfig.IncludeNullValues = true;
JsConfig.ExcludeTypeInfo = true;

Any suggestions? Thanks!

Please post the full DTO that you’re trying to serialize. Also I would very strongly recommend against using Interfaces or object properties on DTO’s, they’re very bad practice and is what’s forcing the serialized JSON to contain ugly type info.

Also note this is an advanced customization that can break deserialization:

JsConfig.ExcludeTypeInfo = true;

Since you’re forcing it to exclude Type Info that C# JSON Deserializers need. If you feel like you need to use it you’re likely using object or Interface properties which should be avoided as mentioned above. So I would remove this config and change your DTO’s to not use Interfaces or object properties.