This section lists the compiler options alphabetically and provides a thorough description of their function.
Specifies the version of the standard used in the input ASN.1 specification files.
The -1990 option indicates that the ASN.1 specification should contain only syntax that conforms to the 1990 standard.
The -2021 option indicates that the ASN.1 specification should contain only syntax that conforms to a more modern ASN.1 standard than 1990.
Enables the compiler to retain a previous behavior specified by <badcase>. Use this option sparingly, only when it is absolutely necessary for a specific task.
Instructs the ASN.1/C# compiler to use explicit automatic tagging not only for untagged but also for tagged CHOICE types, open types, and "DummyReference" types, based on the interpretation of clause 31.2.7 c of the X.680 2002 ASN.1 standard.
In the following example, if -allow BadExplicitAutomaticTagging is specified, the compiler uses explicit automatic tagging for the ch field that has the tagged CHOICE type. If -allow BadExplicitAutomaticTagging is not specified, the compiler uses implicit tagging for this field.
B4114 DEFINITIONS AUTOMATIC TAGS ::= BEGIN Seq ::= [65] SEQUENCE { ch Cho } Cho ::= [65] CHOICE { b BOOLEAN } s Seq ::= { ch b : TRUE } END
The -allow BadExplicitAutomaticTagging compiler option is available in version 4.5 and later.
Instructs the ASN.1 compiler to process type and value assignments found outside input modules.
Module1 DEFINITIONS ::= BEGIN MyInt ::= INTEGER END ExtraModularType ::= INTEGER Module2 DEFINITIONS ::= BEGIN MyBit ::= INTEGER END
If the -assignments option is not specified, the ASN.1 compiler issues an error because ExtraModularType is outside the bounds of BEGIN and END.
Enables or disables code generation for automatic decoding of ASN.1 open types, such as resolving types using ASN.1 component relation constraints.
Instructs the compiler to generate additional C# code that implements parsing of ASN.1 value notation data into C# objects that represent values defined by value notation.
When the -avn option is specified, the compiler generates two additional C# classes in the ValueNotationParser.cs source file:
By default, the -avn option is disabled.
Specifies the encoding rules available at runtime:
Currently, the OSS ASN.1 Tools for C# does not support CER.
The -cxer compiler option is available in version 4.4 and later.
The -exer compiler option is available in version 4.3 and later.
The -cper and -cuper compiler options are available in version 4.6 and later.
Specifies the name of a text file that contains command-line options. The compiler reads the specified file and treats the options as if they were found on the command line.
Instructs the compiler to generate files compatible with previous versions of the OSS ASN.1 compiler. This option takes a single operand or flag, and can be specified more than once.
The following table contains the -compat flags listed alphabetically and provides a description.
Name | Description |
---|---|
NoSeparatePduWrapperClasses |
The same as the v4.0.0 flag. |
ManglePduClassNameWhenDirectiveUnsupported |
Prior to version 4.7.0,
the PDU class names could depend on the presence of the directives that were applied to the ASN.1 types but were not supported and therefore were ignored.
The following example demonstrates what has been changed:
--<ASN1.DeferDecoding M.S.s>-- M DEFINITIONS ::= BEGIN Foo ::= OCTET STRING S ::= SEQUENCE { s Foo --<NOCOPY>-- } ENDPreviously the SSEncodable class was generated instead of the Foo class for the Foo ASN.1 type. The ManglePduClassNameWhenDirectiveUnsupported flag restores generation of previous PDU class names in this case. |
v4.0.0 |
Generates type representations compatible with applications written for version 4.0. |
v5.0.1ImportedWithSuccessorForwardedReferences |
Restores the behavior of ASN.1 compiler versions prior to version 5.1 and instructs the ASN.1 compiler to not report errors or warnings for some unresolved forwarded references imported using WITH SUCCESSORS. Note that this behavior might cause an error or, in some cases, constraints (for example, contents constraints) specified inside inner subtype constraints applied to a parameterized type whose right-hand side type includes an instance of another parameterized type can be ignored. |
v5.1ArtificialPDUsForRecursivesTypes |
Restores the behavior of ASN.1 compiler versions prior to version 5.1 and instructs the ASN.1 compiler to create new artificial PDUs for complex recursive types defined through a CONSTRAINED BY syntax inside parameterized types. The v5.1ContentsConstraintInsideOpenTypeValue compat flag was added in version 5.1.0.1. |
v5.1ArtificialPDUsForRecursivesTypes |
Restores the behavior of ASN.1 compiler versions prior to version 5.1 and instructs the ASN.1 compiler to create a new artificial PDU for a type with contents constraint inside an open type value even when a matching type exists in the information object set specified in the component relation constraint. The v5.1ContentsConstraintInsideOpenTypeValue compat flag was added in version 5.1.0.1. |
v5.1ForwardedNonParamReferencesImportedWithSuccessors |
Restores the behavior of ASN.1 compiler versions prior to version 5.1 and instructs the ASN.1 compiler to skip some forwarded non-parameterized references that are defined later, are imported using WITH SUCCESSORS, and included inside actual parameters with inner subtype constraints in instances of parameterized types. This behavior might cause warnings in relaxed mode or errors in non-relaxed mode. The v5.1ForwardedNonParamReferencesImportedWithSuccessors compat flag was added in version 5.1.0.1. |
v5.1ConstrainedIntegerTypes |
Restores the behavior of ASN.1 compiler versions prior to version 5.1 and instructs the ASN.1 compiler to generate the following:
|
v5.1.0 |
Provides compatibility with version 5.1.0 of the ASN.1 compiler. The v5.1.0 flag is equivalent to the following -compat options: v5.1ConstrainedIntegerTypes and v4.0.0. |
v5.2.0 |
Provides compatibility with version 5.2.0 of the ASN.1/C# compiler. The v5.2.0 flag is equivalent to the v5.2TypesFromConstrainedBy and v5.2PdusForTypesFromDEFAULTInsideInfoObjClass -compat options. |
v5.2PdusForTypesFromDEFAULTInsideInfoObjClass |
Restores the behavior of ASN.1 compiler versions prior to version 5.2 and instructs the ASN.1 compiler to disambiguate conflicting PDU names with an additional module name for types used in a DEFAULT syntax applied to VariableTypeFields inside information object classes. |
v5.2TypesFromConstrainedBy |
Restores the behavior of ASN.1 compiler version prior to version 5.2. This flag instructs the ASN.1 compiler to generate names that were generated by previous versions of the ASN.1 compiler for types defined in a CONSTRAINED BY syntax. Note that this compat flag could restore an unexpected circular reference error for some syntaxes. |
Specifies whether constraint validation code is generated. When -noCostraints is used, the size of the generated code is smaller and can be executed faster.
Instructs the ASN.1 compiler to generate additional warning messages for protocol designers writing ASN.1 specifications.
Additional warning messages are issued if:
Instructs the ASN.1 compiler to enable partial decoding, in addition to standard decoding. Encoding is not affected.
The -enablePartialDecode option is supported by the BER, DER, PER, UPER, CPER, CUPER, OER, and COER encoding rules.
By default, the -enablePartialDecode option is disabled.
Controls the presence of encoder and decoder methods in generated PDU classes.
Reduce the code size of classes generated with the encoder or decoder methods by using the -encodeonly or -decodeonly compiler option, respectively.
These options are available in version 4.4 and later.
Instructs the compiler to redirect all ASN.1 compiler messages to <file>. This is useful on platforms where you cannot redirect stdout and stderr to a file.
Instructs the ASN.1 compiler to generate a .gen file that captures all directives from the ASN.1 input file as well as directives for names produced by the compiler (_setof1, for example).
The optional operand genfile specifies the name of the .gen file. If the filename is not specified, the ASN.1 compiler generates one from the last ASN.1 input file specified on the command line and substitutes .asn with .gen.
Generates C# serialization attributes that include additional ASN.1 schema information, such as original names, optionality, etc., and can be helpful for text XML or JSON serialization formats.
Note: When generating C# classes that will be used with .NET Standard, do not specify the -genschemainfo compiler option. This option generates C# attributes that are not supported by .NET Standard.
Instructs the ASN.1 compiler to generate the OSS-specific SizeAttribute and ValueRangeAttribute attributes that include the minimum and maximum values of all permitted counts, lengths, or values computed based on subtype constraints applied to the corresponding ASN.1 types.
Example:
Typically, attributes are attached to properties associated with classes that represent ASN.1 types with size or value range constraints. Attributes that correspond to constrained ASN.1 types that are defined as elements of SEQUENCE OF and SET OF types are attached to their parent collection class. Attributes can be retrieved by an application using C# Reflection at runtime.
SizeAttribute is generated for the following types with size constraints:
SizeAttribute stores the effective minimum value in the Min property and the effective maximum value in the Max property. The C# "int" type has values between 0 and INT_MAX (2147483647). An additional IsExtensible property returns true if the corresponding size constraint is extensible, for example, (SIZE(1..2, ...)).
For semi-bounded size constraints, the Max property has the int.MaxValue value.
ASN.1 | C# |
---|---|
name IA5String (SIZE(10..MAX)) |
[Oss.Asn1.Size(10, int.MaxValue, false)] public string Name { get; set; } |
ValueRangeAttribute is generated for INTEGER types that have value range constraints and are not marked with a HUGE directive. The attribute stores the effective minimum value in the Min property and the effective maximum value in the Max property. The Min and Max properties have the C# "object" type. An additional OperandType property can be used to determine the actual C# integer type that can be either an "int", "long", or "ulong" type. The IsExtensible property returns true if the corresponding value range constraint is extensible.
You can access the minimum and maximum values of the Min and Max properties as follows:
if (rangeAttr.OperandType == typeof(int)) int min = (int)rangeAttr.Min; int max = (int)rangeAttr.Max; } ...
For value ranges with MIN and/or MAX effective bounds, the long.MinValue and/or long.MaxValue values are generated:
ASN.1 | C# |
---|---|
valueMin INTEGER (MIN..50) valueMax INTEGER (10..MAX) |
[Oss.Asn1.ValueRange(long.MinValue, (long)50, false)] public long ValueMin { get; set; } [Oss.Asn1.ValueRange(long)10, long.MaxValue, false)] public long ValueMax { get; set; } |
ASN.1 | C# |
---|---|
Bcas DEFINITIONS ::= BEGIN BBCard ::= SEQUENCE { name IA5String (SIZE (1..60)), age INTEGER (1..100, ...), positions SEQUENCE (SIZE(2)) OF IA5String (SIZE (1..30)) } END |
public partial class BBCard : Oss.Asn1.BasePdu { [Oss.Asn1.Size(1, 60, false)] public string Name { get; set; } [Oss.Asn1.ValueRange((int)1, (int)100, true)] public int Age { get; set; } [Oss.Asn1.Size(1, 30, false)] public partial class PositionsType : System.Collections.Generic.List<string> [Oss.Asn1.Size(2, 2, false)] public PositionsType Positions { get; set; } |
Displays a list of all command-line options.
By entering asn1cs -help you can obtain a summary of valid command-line options:
OSS ASN.1/C# Compiler Version 5.3 Copyright (C) 2023 OSS Nokalva, Inc. All rights reserved. Compiler parameters: (.D. indicates default) <input> <...input> . one or more ASN.1 input files -syntax ... perform syntax checking only -output name ... use name for generated output -nooutput ... do not generate output files, same as syntaxonly. -errorfile file ... write all messages to 'file' instead of stdout/stderr -path <path> ... use base directory 'path' for generated output -names schemacase | -names camelcase ... select conversion method of ASN.1 names to C# names -namespace <name>... use namespace 'name' for generated classes -list <listfile> ... generate an ASN.1 combined listing into 'listfile' -nolist .D. do not generate an ASN.1 combined listing -mod <listfile> ... generate single ASN.1 module listings into 'listfile' -nomod .D. do not generate single ASN.1 module listings -gendir <genfile>... generate list of directives into <genfile> -uniquepdu .D. check that pdu id's are unique -nouniquepdu ... do not check that pdu id's are unique -prefix id ... prefix variables with unique id -constraints .D. check constraints at runtime -noconstraints ... do not check constraints at runtime -valuerefs .D. generate C# values for all valuereferences -novaluerefs ... do not generate C# values for all valuereferences -encodeonly ... generate only encoder methods -decodeonly ... generate only decoder methods -test ... generate a program to encode/decode ASN.1 values -notest .D. do not test encoding/decoding of all ASN.1 values -warning ... allow warning messages -nowarning ... suppress warning messages -suppress msg# ... suppress a specific message -verbose ... display compilation progress messages -noverbose .D. do not display compilation progress messages -pedantic ... rigorously check all modules -nopedantic .D. rigorously check only the root module(s) -relaxedMode .D. automatically select command-line options that result in relaxed compiler behavior, for example, -noWarning, etc. -norelaxedMode ... automatically select command-line options that result in strict compiler behavior -informatory ... allow informatory messages -noinformatory ... suppress informatory messages -ignoreError msg# .. ignore a specific error (issue a warning instead) -designerWarnings .. issue additional warnings for protocol designers -compat version# ... disable new features for backward compatibility -allow badcase ... enable badcases for backward compatibility -1990 ... all modules conform to 1990 ASN.1 syntax -2021 .D. all modules conform to 2021 ASN.1 syntax -per ... generate output for Aligned PER -cper ... generate output for Canonical Aligned PER -uper ... generate output for Unaligned PER -cuper ... generate output for Canonical Unaligned PER -ber .D. generate output for BER -der ... generate output for DER -xer ... generate output for XER -cxer ... generate output for Canonical XER -exer ... generate output for Extended XER -oer ... generate output for OER -coer ... generate output for Canonical OER -json ... generate output for JSON -commandfile <file> ... read command line from 'file' -root ... treat all modules as root modules -keepnames ... generate directives for keeping names -sampleCode <pdus|values> ... generate a sample code to initialize, encode, decode and traverse values of PDU types defined in the input ASN.1 syntax -noSampleCode ... do not generate a sample code -autoencdec .D. generate metadata for automatic decoding of open types -noautoencdec ... do not generate metadata for automatic decoding of open types -messageFormat <format> ... display error messages in <format>: 'oss', 'emacs' or 'msvc' -assignments ... process type and value assignments defined outside ASN.1 modules -helperAPI ... generate specific helper API's selected via a keyword: 'pdudecoder' - helper API's for PDU decoding -noHelperAPI ... do not generate specific helper API's selected via a keyword: 'pdudecoder' - helper API's for PDU decoding -ignoreIncompleteItems ... ignore incomplete ASN.1 definitions of types and values -ignoreRedefinedAssignments ... ignore redefined ASN.1 definitions of types and values -reservedWords <reserved_words> ... treat words specified in the parameter and separated by commas as reserved words in the generated files that should be always mangled -singlefile ... generate a single output file instead of a set of output files containing a single class each -singlens ... generate all the code into a single namespace -genschemainfo ... generate attributes with schema information -noserializable ... do not generate Serializable attributes -enablePartialDecode ... generate time-optimized full and partial decoders -partialDecodeOnly ... generate time-optimized partial decoder only -avn ... generate output for ASN.1 value notation parser -genSizeValueRangeAttributes ... generate attributes for effective size constraints and effective value ranges applied to INTEGER types -nullableReferenceTypes ... enable C# nullable reference types -noNullableReferenceTypes .D. disable C# nullable reference types .. Sep 1 2023 ..
You can obtain a synopsis of the command-line syntax by entering asn1cs with no arguments:
OSS ASN.1/C# Compiler Version 5.3 Copyright (C) 2023 OSS Nokalva, Inc. All rights reserved. asn1cs <infile(s)> [-errorfile file ] [-list listingfile | -nolist ] [-ber] [-commandfile file ] [-mod listingfile | -nomod ] [-der] [-1990 | -2021 ] [-output name | -noout ] [-oer] [-test | -notest ] [-relaxedMode | -norelaxedMode] [-coer] [-suppress msg# ] [-constraints | -noconstraints] [-per] [-ignoreError msg# ] [-autoencdec | -noauto ] [-uper] [-allow badcase ] [-valuerefs | -novaluerefs ] [-cper] [-assignments ] [-encodeonly | -decodeonly ] [-cuper] [-noserializable ] [-pedantic | -nopedantic ] [-json] [-designerWarnings ] [-uniquepdu | -nouniquepdu ] [-xer] [-warning | -nowarning] [-sampleCode | -noSampleCode ] [-exer] [-verbose | -noverbose] [-messageFormat format ] [-avn] [-inform | -noinform ] [-reservedWords <words> ] [-namespace <name> ] [-ignoreIncompleteItems ] [-root] [-prefix id ] [-ignoreRedefinedAssignments ] [-syntax] [-genschemainfo ] [-genSizeValueRangeAttributes ] [-names schemacase |-names camelcase ] [-enablePartialDecode |-partialDecodeOnly ] [-nullableReferenceTypes|-noNullableReferenceTypes ] enter "asn1cs -help" for more information
Enables generation of the service PDU decoder class so PDUs can be decoded without explicit specification of the PDU type.
Automatic detection of the incoming message type is available in the BER, DER, XER, and CXER codecs.
This option is available in version 4.4 and later.
Instructs the ASN.1 compiler to treat certain errors as warnings.
This option is especially useful for application developers that need to generate a header file and a control table or code file without correcting the ASN.1 specification. Note that the values generated in the control table or code file are not valid according to the ASN.1 standard.
You can ignore the following message numbers: 49, 76, 77, 305, 319, 811, 832, 1078, 1130, 1162, 1207, 1211.
Instructs the ASN.1 compiler to treat certain errors related to undefined ASN.1 types and values as warnings, and to ignore incomplete ASN.1 definitions that directly or indirectly reference undefined ASN.1 types and values.
This option helps application developers to generate a header file and a control table or code file without correcting the ASN.1 specification, when undefined and incomplete ASN.1 items are not used by the application. Note that the compiler will not consider the ASN.1 types that are referenced only by ignored incomplete types as PDUs, unless you apply the PDU directive.
To see the incomplete items ignored by the compiler, use the -verbose option.
In this example, S is incomplete because B is not defined:
M DEFINITIONS ::= BEGIN S ::= SEQUENCE { a A, b B } A ::= INTEGER END
Instructs the ASN.1 compiler to ignore all duplicate definitions within the same ASN.1 module, and to issue warnings instead of errors.
-relaxedMode implies the -ignoreRedefinedAssignments option.
Informs the compiler whether it should generate informatory messages.
When you use -relaxedMode or -noWarningMessages, the -noInformatoryMessages option is implied.
Creates a directive file (.gen file) to preserve generated type identifiers in subsequent compilations.
The ASN.1 compiler might generate different names for a given type each time the schema is compiled, which requires further changes in your code. To avoid this, use the -keepNames option. When the schema is recompiled, specify the previously created .gen file as the first input file at the command line.
Specifies whether the compiler should generate an ASN.1 composite listing of root modules, containing all macro instances and parameterized items expanded, and all external references resolved into <listfile>.
The listing file contains valid ASN.1 and can be used as input to any ASN.1 compiler. If you don't specify it, the default name is the last command-line input filename, with the .lst extension.
Controls the format of the error, warning, or informatory messages issued by the ASN.1 compiler for further parsing by a compatible text editor. This helps you automatically find the location in the input file for which the message was issued.
Three format schemes are available:
Instructs the compiler to generate a module listing file that contains information from multiple ASN.1 modules.
Controls names mapping from ASN.1 schema to C# types/variables.
By default, names is not specified, dashes are removed and the first letter is capitalized, for example:
ASN.1: one-two-XML --> C#: OneTwoXML.
If -names schemacase is specified, dashes are converted to underscores and capitalization is preserved, for example:
ASN.1: DL-CCCH-Message --> C#: DL_CCCH_Message.
If -names camelcase is specified, dashes are removed, the first letters are capitalized, and the rest are lowercased:
ASN.1: one-two-XML --> C#: OneTwoXml.
Specifies a custom <name> to be used for the generated code namespace; it replaces MySchema in the MySchema.MyModule pattern.
Disables generation of the [System.Serializable] attribute for .NET frameworks or platforms that do not support it (for example, Windows Phone).
The -noSerializable compiler option can also be specified to instruct the compiler to generate C# classes compatible with .NET Standard.
Instructs the ASN.1/C# compiler to generate a nullable aware context with nullable reference types for the following schema fields:
Previously, only C# nullable value types were supported for the following ASN.1 simple types: BOOLEAN, INTEGER, NULL, ENUMERATED, and REAL.
When -nullableReferenceTypes option is specified, each generated C# file includes a "#nullable enable annotations" directive. Variables with nullable reference types are generated with a "?" nullable modifier. A C# compiler that supports C# language version 8.0 or later (available in Visual Studio 2019 or later) must be used during compilation.
ASN.1 | Type.cs |
---|---|
Mod DEFINITIONS ::= BEGIN BBCard ::= SEQUENCE { name IA5String OPTIONAL, age INTEGER DEFAULT 20, ..., positions SEQUENCE OF IA5String } END |
/// <summary>Field 'name'</summary> public string? Name { get; set; } /// <summary>Field 'age'</summary> public int? Age { get; set; } ... /// <summary>Field 'positions'</summary> public PositionsType? Positions { get; set; } |
Specifies the subfolder <name> where all generated output is placed. The noOutput option suppresses code generation, therefore only syntax checking is performed.
Instructs the compiler to replace standard decoding with partial decoding. In this case, no standard decoding functions are generated.
The -partialDecodeOnly option is supported for the BER, DER, PER, UPER, CPER, CUPER, OER, and COER encoding rules.
By default, the -partialDecodeOnly option is disabled.
Specifies the <path> to where all generated output is placed.
Instructs the ASN.1 compiler to thoroughly check the input file syntax.
If a type is not defined and it is neither directly nor indirectly referenced by the root modules, the compiler does not consider it an error.
-pedantic implies the -syntax option, therefore no code is generated.
Instructs the compiler to generate top-level identifiers with the specified name prefix. This is useful when an application program supports multiple schemas.
When you specify -relaxedMode, the following options are automatically selected:
Instructs the compiler to treat <words> (separated by commas, case-sensitive) as "reserved". This option is useful when certain platforms contain keywords that are not recognized by the OSS ASN.1 compiler as reserved for C#.
Instructs the ASN.1 compiler to treat all input modules as root modules. Consequently, all unreferenced types (they are not referenced by any other type) in all modules are considered PDUs that can be encoded and decoded.
By default, only the last module specified on the command line is treated as a root module.
Enables generation of a test application (a program class with the Main() method) that demonstrates the encoding or decoding of schema types for mockup values (or schema values, if any).
Generates code into a single file rather than one file per class.
Generates code into a single namespace rather than using the MySchema.MyModule naming pattern.
Instructs the compiler to suppress a specific warning or informatory message.
You can specify -suppress more than once on the command line.
<msgN> can be either the complete message identifier (A0210W, for example) or the numeric part (210, for example).
Instructs the ASN.1 compiler to perform only syntax checking, no code is generated.
Enables or disables generation of a test application (a program class with the Main() method), that demonstrates the encoding or decoding and requires at least one ASN.1 value defined in the schema.
Specifies whether Protocol Data Unit (PDU) tags should be unique.
-uniquePDU specifies that the tags for all PDUs must be unique.
-noUniquePDU informs the compiler that PDUs can have identical tags.
By default, when BER or DER is expected to be used at runtime, the compiler issues a warning message upon detecting duplicate PDU tags.
Note that in certain ASN.1 specifications such as the Presentation Layer Protocol (ISO/IEC 8823/ITU-T X.226), PDUs don't have unique tags. In other ASN.1 specifications, such as the Association Control Service Element (ACSE), PDU tags are unique.
Enables or disables generation of C# classes for values defined in the schema.
Specifies whether ASN.1 compiler status messages should be issued.
The -verbose option instructs the ASN.1 compiler to issue status messages, such as the name of the current input file.
Specifies whether compiler warning and informatory messages should be generated.
This documentation applies to the OSS® ASN.1 Tools for C# release 5.3 and later.
Copyright © 2024 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.