ASN.1 Debugging/Printing

Applies to: ASN.1/C# v5.1-

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 can use

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

    The following message is printed 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 ValueNotationFormatter runtime trace or print class: every C# representation type can be printed or 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 5.1 and later.

Copyright © 2022 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.