Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

466
Vistas
Debugging when deserializing a Json file with JsonConvert

Is there a way to "debug a Json file" at deserialisation using JsonConvert?
It would be very useful if the line (or group of lines) of the Json file being processed could be printed as a debug option.
Otherwise, when the deserialisation of a Json file into an object fails, it can be very difficult to figure out what is wrong with that file.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You can implement a custom TraceWriter that logs to console as deserialization goes on, like this. Of course you could also wrap it into a log4net log entry or just do whatever you like.:

public class ConsoleTraceWriter : ITraceWriter
{    
    public TraceLevel LevelFilter
    {
        // trace all messages
        get { return TraceLevel.Verbose; }
    }

    public void Trace(TraceLevel level, string message, Exception ex)
    {
        if (ex != null) {
            Console.WriteLine(level.ToString() + ": " + message + " Ex: " + ex.Message);
        } else {
            Console.WriteLine(level.ToString() + ": " + message);
        }
    }
}

And set it at deserialization

JsonConvert.DeserializeObject(myJson, new JsonSerializerSettings { TraceWriter = new ConsoleTraceWriter() });
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda