Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/12/10 09:45:45 (15 years ago)
Author:
epitzer
Message:

more descriptive persistence error message (#548)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Persistence/3.3/Core/Serializer.cs

    r3005 r3007  
    1010using System.Reflection;
    1111using System.IO;
     12using System.Diagnostics;
    1213
    1314namespace HeuristicLab.Persistence.Core {
     
    140141    }
    141142
     143    private Stack<string> objectGraphTrace = new Stack<string>();
     144
    142145    private IEnumerator<ISerializationToken> Serialize(DataMemberAccessor accessor) {
     146     
    143147      object value = accessor.Get();
    144148      if (value == null)
     
    159163      }
    160164      try {
     165        objectGraphTrace.Push(accessor.Name);
    161166        IPrimitiveSerializer primitiveSerializer = configuration.GetPrimitiveSerializer(type);
    162167        if (primitiveSerializer != null)
     
    182187          return new List<ISerializationToken>().GetEnumerator();
    183188        } else {
    184           throw x;
    185         }
     189          throw;
     190        }
     191      } finally {
     192        objectGraphTrace.Pop();
    186193      }
    187194    }
     
    191198      sb.Append("Could not determine how to serialize a value of type \"")
    192199        .Append(type.VersionInvariantName())
    193         .AppendLine("\"");
    194       sb.AppendLine("No registered primitive serializer for this type:");
     200        .AppendLine("\"")
     201        .Append("object graph location: ")
     202        .AppendLine(string.Join(".", objectGraphTrace.ToArray()))
     203        .AppendLine("No registered primitive serializer for this type:");
    195204      foreach (var ps in configuration.PrimitiveSerializers)
    196205        sb.Append(ps.SourceType.VersionInvariantName())
     
    205214          .Append(cs.GetType().VersionInvariantName())
    206215          .AppendLine(")");
    207       return new PersistenceException(sb.ToString());             
     216      return new PersistenceException(sb.ToString());
    208217    }
    209218
Note: See TracChangeset for help on using the changeset viewer.