ASN.1 Debugging/Printing

Applies to: ASN.1/C# 4.5

ASN.1 encoding/decoding is always performed on the entire PDU/message, which often consists of a large number of elements organized in a complex structure. When encoding/decoding fails, finding which element caused the error might be difficult. To make encoding/decoding easier to troubleshoot, you have two options:

  • The compiler -debug option generates additional code so the ASN.1 PDU/field information (names/types) is included in the exception Message, if one was thrown. Note that the -debug option is on by default, use –noDebug to turn it off. The following code will throw an exception:
        Bcas.BCASModule.BBCard pdu = Bcas.BCASModule.Values.MyCard;
        pdu.Team = null; // just to cause the exception
    catch (Exception e) 

    and will print to the console:

    Object reference not set to an instance of an object, field 'team' (type:
    IA5String) of PDU 'BBCard'; C# object: BBCard.Team.
  • The runtime ValueNotationFormatter trace/print class: every C# representation type can be printed/converted into an ASN.1 value string using ToString() or the ValueNotationFormatter class, which offers more formatting options. For example:
     using VNF = Oss.Asn1.ValueNotationFormatter;
     . . .
    // two lines below are equivalent
    // print with options
    VNF.Options.IndentSize = 10;
    VNF.Options.NewLine = "\n";
    // log to file
    StreamWriter log = new StreamWriter("log.txt");
    VNF.Print(pdu, log);

This documentation applies to the OSS® ASN.1 Tools for C# release 4.5 and later.

Copyright © 2017 OSS Nokalva, Inc. All rights reserved.
No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means electronic, mechanical, photocopying, recording or otherwise, without the prior permission of OSS Nokalva, Inc.
Every distributed copy of the OSS® ASN.1 Tools for C# is associated with a specific license and related unique license number. That license determines, among other things, what functions of the OSS ASN.1 Tools for C# are available to you.