ASN1C C# Command Line Options

The following table shows a summary of the command line options that have meaning when C# code generation is selected:

Option Argument Description
-allow-ambig-tags   This option suppresses the check that is done for ambiguous tags within a SEQUENCE or SET type within a specification. Special code is generated for the decoder that assigns values to ambiguous elements within a SET in much the same way as would be done if the elements were declared to be in a SEQUENCE.
-asnstd

x680
x680-2021
x680-2015
x680-2008
mixed
x208

This option selects the version of ASN.1 syntax to be parsed. ‘x680’ (the default) refers to modern ASN.1 as specified in the ITU-T X.680-X.690 series of standards. Refer to the section called “ASN.1 Standard Revisions” for more information.
-ber None This option instructs the compiler to generate functions that implement the Basic Encoding Rules (BER) as specified in the ASN.1 standards.
-c# None Generate C# source code.
-cer None This option instructs the compiler to generate functions that implement the Canonical Encoding Rules (CER) as specified in the ASN.1 standards.
-coer None This option is used to generate encode/decode methods that implement the Octet Encoding Rules (OER) such that encodings are canonical and decodings are expected to be canonical.
-compact None This option instructs the compiler to generate more compact code at the expense of some constraint and error checking. This is an optimization option that should be used after an application is thoroughly tested.
-compat <versionNumber>

Generate code compatible with an older version of the compiler. The compiler will attempt to generate code more closely aligned with the given previous release of the compiler.

<versionNumber> is specified as x.x (for example, -compat 5.2)

-config <filename> This option is used to specify the name of a file containing configuration information for the source file being parsed. A full discussion of the contents of a configuration file is provided in the section called “Compiler Configuration File”
-csfile *.cs or a specific .cs file name If valued with *.cs, indicates that ASN1C is to generate one .cs file for each ASN.1 module processed. If valued with a specific .cs file name, indicates that ASN1C is to generate one .cs file to hold all code. Do not specify any folder information in the -csfile value; use the -o qualifier instead.
-cskeyfile strongly named key file This option is used to specify the name of a strongly named key file (usually a .snk file) that contains a signature to be used to sign an assembly. If used along with the -genmake option, the generated makefile will contain instructions to sign the assembly with the key file. If used along with the -vcproj option, the generated project file will contain instructions to sign the assembly with the key file.
-depends None This option instructs the compiler to generate a full set of C# source files that contain only the productions in the main file being compiled and items those productions depend on from IMPORT files.
-der None This option instructs the compiler to generate functions that implement the Distinguished Encoding Rules (DER) as specified in the ASN.1 standards.
-dirs None This is a C# option that causes a subdirectory to be created to hold each of the generated C# source files for each module in an ASN.1 source file.
-dotnetv5 None Generate .NET v5 .csproj files (if used with -vcproj). If not specified, .NET v4 .csproj files will be created.
-dotnetv6 None Generate .NET v6 .csproj files (if used with -vcproj). If not specified, .NET v4 .csproj files will be created.
-dotnetv7 None Generate .NET v7 .csproj files (if used with -vcproj). If not specified, .NET v4 .csproj files will be created.
-events None Generate extra code to invoke user defined event and error handler callback methods (see section the section called “Event Handlers”).
-genmake None This option is used to generate a makefile for compiling generated classes using nmake command from within a Visual Studio .NET command prompt window.
-genmetadata None This option is used to generate methods to permit accessing metadata about SEQUENCE and SET types. Users may query value ranges (represented as Asn1ValueRange objects) and optional/required status for elements in the given SEQUENCE or SET.
-genTest or -test None

This option causes test code to be generated that will populate a PDU object with random test data. This code will be embedded in the body of a generated writer program; thus the option only results in code being generated if -writer is also specified.

-I <directory> This option is used to specify a directory that the compiler will search for ASN.1 source files for IMPORT items. Multiple –I qualifiers can be used to specify multiple directories to search.
-json or -jer None This option is used to generate encode/decode functions that implement the Javascript Object Notation (JSON) Encoding Rules (JER) as specified in the X.697 ASN.1 standard. (Note: -jer+ is no longer supported. Similar functionality is now standard JER.)
-lax None This option instructs the compiler to not generate code to check constraints. When used in conjunction with the –compact option (described next), it produces the smallest code base for a given ASN.1 specification.
-list None Generate listing. This will dump the source code to the standard output device as it is parsed. This can be useful for finding parse errors.
-namespace <namespaceName> This is a C# option that allows the entire C# namespace to be changed. Instead of the module name, the full name specified using this option will be used. This option cannot be used in conjunction with –nspfx option.
-noaccomment None This option suppresses the generation of the comment that shows the asn1c command that was used to generate the code.
-nodecode None This option suppresses the generation of decode functions.
-noencode None This option suppresses the generation of encode functions.
-noevents None This option supresses generation of event handling code that is generated by default to enable element tracking, a feature used to enhance error reporting.
-noIndefLen None This option instructs the compiler to omit indefinite length tests in generated decode functions. These tests result in the generation of a large amount of code. If you know that your application only uses definite length encoding, this option can result in a much smaller code base size.
-noOpenExt None This option instructs the compiler to not add an open extension element in constructs that contain extensibility markers. The purpose of the element is to collect any unknown items in a message. If an application does not care about these unknown items, it can use this option to reduce the size of the generated code.
-noPLMN None If not specified, if the ASN.1 contains a production named PLMNidentity (any case), that production will be treated as an OCTET STRING, regardless of how it may be defined in the ASN.1. But if -noPLMN is specified, this special recognition of PLMNidentity will be disabled, and it will be treated according to its definition in the ASN.1 (frequently TBCD-STRING, although in most cases that is incorrect).
-noTBCD or -noBCD None Disable special treatment of BCD and TBCD strings.
-noUniqueNames None

Turn off the capability to automatically generate unique names to resolve name collisions in the generated code. Name collisions can occur, for example, if two modules are being compiled that contain a production with the same name. A unique name is generated by prepending the module name to one of the productions to form a name of the form <module>_<name>.

Note that name collisions can also be manually resolved by using the typePrefix, enumPrefix, and valuePrefix configuration items (see the Compiler Configuration File section for more details)

-nspfx <prefixName> This is a C# option for adding a prefix in front of the assigned C# namespace name. By default, the C# namespace name is set to the module name. If the namespace is embedded within a hierarchy, this option can be used to set the prefix that must be added to allow C# to find the class definition.
-o <directory> This option is used to specify the name of a directory to which all of the generated files will be written.
-oer None

Generate functions that implement the Octet Encoding Rules (OER) as specified in the ASN.1 standards.

-oid-as-string None Use string to represent OBJECT IDENTIFIER and RELATIVE-OID values. The strings must be in dotted-number format (e.g. "0.5.1234").
-pdu <typeName>

Designate given type name to be a Protocol Definition Unit (PDU) type. By default, PDU types are determined to be types that are not referenced by any other types within a module. This option allows that behavior to be overridden.

The * wildcard character may be specified for <typeName> to indicate that all productions within an ASN.1 module should be treated as PDU types.

-per None This option instructs the compiler to generate functions that implement the Packed Encoding Rules (PER) as specified in the ASN.1 standards.
-genPrint -print None This option specifies that print methods should be generated. Print
-sax None This option instructs the compiler to generate code that uses the old SAX XML parser API. The default is to use the C# XmlReader API.
-shortnames None This option is used to change the name generated by compiler for embedded types in constructed types. This option is required to handle the limit on the size of filenames in certain situations. With this option, the generated code filenames would be shorter than without this option.
-stream None This option instructs the compiler to generate stream-based encoders/ decoders instead of memory buffer based. This makes it possible to encode directly to or decode directly from a source or sink such as a file or socket. In the case of BER, it will also cause forward encoders to be generated, which will use indefinite lengths for all constructed elements in a message.
-tables None This option is used to generate additional code for the handling of table constraints as defined in the X.682 standard.
-use-enum-types None

This option instructs the compiler to generate an enum along with ints when a collection of named integers is encountered in the ASN.1.

-vcproj <version> This option instructs the compiler to generate a Visual Studio C# project file. <version> is the version of Visual Studio (2022, 2019 (default), 2017, 2015, 2013, 2012, 2010, 2008, 2005). For 2019 or higher a project file that targets .NET v5 will be generated. For 2017 or lower a project file that targets .NET Framework v4 will be generated.
-warnings None Output information on compiler generated warnings.
-xer None This option instructs the compiler to generate functions that implement the XML Encoding Rules (XER) as specified in the ASN.1 standards. Related XML Schema can be produced by using the -xsd command line option.
-xml None This option instructs the compiler to generate functions that implement the XML Encoding Rules (XML) as specified in the World-Wide Consortium (W3C). Related XML Schema can be produced by using the -xsd command line option.