Dotfuscator User's Guide
Shelf Life Check

Shelf Life is an application inventory management function that allows you to embed expiration, or de-activation, and notification logic into an application. Dotfuscator injects code that reacts to application expiration by exiting the application and/or sending a PreEmptive Analytics message. This feature is particularly helpful with beta applications. Users can schedule an application’s expiration/de-activation for a specific date and optionally issue warnings to users that the application will expire/de-activate in a specific number of days.

Note: Using Shelf Life requires a Shelf Life Token, which is generated from a Shelf Life Activation Key, purchased separately. For more information, see the Shelf Life Tokens section.

Each Shelf Life Check defines an expiration date and optionally a warning date. When the Check runs, the result is one of three cases:

The exact semantics of what each of those periods mean depends on the application code's Sinks (see below)

To indicate where in your application's code you would like to place a Shelf Life Check, annotate the method with the InsertShelfLife attribute, either by using a Dotfuscator GUI, or by placing the attribute in your code:

Copy Code
    ActivationKeyFile = @"C:\Keys\MyShelfLifeActivationKey.slkey",
    ExpirationDate = "2017-01-01",
    ExpirationNotificationSinkElement = SinkElements.DefaultAction // exit the application if expired
public void DoStuff() { ... }

InsertShelfLife attributes are not required at runtime; therefore, Dotfuscator strips them from the output application.

At runtime, if the injected Check detects the application is being used beyond a warning or expiration date, it can notify the application and send telemetry reporting the issue.

Activation Key

All Shelf Life attributes must specify the path to a Shelf Life Activation Key file.

The InsertShelfLife attribute defines one property for this purpose:

This property is described in more detail in the InsertShelfLifeAttribute section of the custom attribute reference.


In order to use Shelf Life, the application must have access to a Shelf Life Token. Tokens are generated by Dotfuscator using a Shelf Life Activation Key, which is provided by PreEmptive Solutions. For more details on using Tokens, including how to dynamically load them at application runtime, see the Shelf Life Tokens section.

The InsertShelfLife attribute defines four properties telling Dotfuscator how to generate a Token at build time:   

It also defines three properties for dynamically loading the Token at application runtime:

These properties are described in more detail in the InsertShelfLifeAttribute section of the custom attribute reference.

Expiration and Warning Dates

Each Shelf Life check has an associated Expiration Date and Warning Date. These are either specified by the properties of the InsertShelfLife attribute (if the Token is generated at build time) or in the Generate New Shelf Life Token dialog (if the Token is dynamically loaded).

A date is specified as a string, in one of two formats:

For instance, if the build is done on August 1, 2016, and the expiration should be on August 31, 2016, the Expiration Date can be written either "2016-08-31" or "30". 

The Expiration Date must be specified.

The Warning Date, if not specified, is equal to the Expiration Date. Otherwise it must be before the Expiration date.

Application Notification

After the Check occurs, the result can be given to application code via two sinks: the Expiration Notification Sink, and the Warning Notification Sink. These respectively reflect whether the application has expired and whether it is in the warning period. For an overview of Sinks, see the Application Notification section.

The InsertTamperCheck attribute defines three properties for specifying an Expiration Notification Sink:

It also defines three properties for specifying a Warning Notification Sink:

These properties are described in more detail in the InsertShelfLifeAttribute section of the custom attribute reference.

The Notification Sink settings are optional. If both sets are omitted, the application is not notified when the Shelf Life Check is executed.

If the ExpirationNotificationSinkElement is set to DefaultAction, Dotfuscator injects code that exits the application if shelf life expiration is detected.

If the WarningNotificationSinkElement is set to DefaultAction, Dotfuscator does not inject any code to handle the warning notification.

String Sinks

In addition to the normal Application Notification options that pass or set a boolean value in the application code, the Shelf Life Check also permits method and delegate Sinks to have the signature void(string,string). In that case, the following parameters will be passed, in order:

This allows the application code to be more specific in its reaction. For instance, the application can display the expiration date to the user.

Important: Sinks are always called, even if the application is not in the warning period nor has expired.

An example is shown below, mixing both a boolean Sink (for expiration) and a string Sink (for warning).

InsertShelfLifeAttribute Usage with WarningNotificationSink and ExpirationNotificationSink
Copy Code
class ShelfLifeSample {
   bool instanceShelfLifeExpirationFlag;
      ActivationKeyFile = "C:\\shelflife.slkey",
      ExpirationDate = "2018-01-01",
      ExpirationNotificationSinkElement = SinkElements.Field,
      ExpirationNotificationSinkName = "instanceShelfLifeExpirationFlag",
      WarningDate = "2017-12-01",
      WarningNotificationSinkElement = SinkElements.Method,
      WarningNotificationSinkName = "CheckShelfLifeWarning"
   private void Verify() {
     // Dotfuscator will add Shelf Life expiration and warning detection and notification code here
   private CheckShelfLifeExpirationState() {
      if ( instanceShelfLifeExpirationFlag ) {
         // app has expired
      else {
         // app has not expired
   private CheckShelfLifeWarning(string warnDate, string expDate) {
      // use date strings directly
      Console.WriteLine("ShelfLifeSample expires on " + expDate);
      // or parse to datetime to do calculations
      int daysLeft = DateTime.Parse(expDate).Subtract(DateTime.Now);
      Console.WriteLine("ShelfLifeSample will expire in " + daysLeft + " days");


Shelf Life Checks support sending telemetry to a PreEmptive Analytics endpoint. Specifically, if the Check detects the application is in the warning period or has expired, it can emit an Application Lifecycle message, enabling tracking of expired or soon-to-expire copies of the software.

Note that Shelf Life Check telemetry may be enabled or disabled for an entire Dotfuscator project using the "Send Shelf Life Messages" Global Setting.

This Global Setting is disabled by default, and must be enabled for telemetry to function.

If telemetry is enabled, and if Analytics has been properly configured and initialized (see Instrumentation Injection), the resulting output application will be ready to send Shelf Life Notifications to a PreEmptive Analytics endpoint.

Telemetry supports extended keys (i.e. user-defined custom data). The InsertShelfLifeattribute defines four properties for specifying an Extended Key Source:

An application can contain any number of InsertShelfLifeattributes. In the event that an application has expired and multiple Checks trigger, multiple Shelf Life messages from the same application session will be sent with the same Shelf Life ID.

Do not put this attribute on the same method containing the Setup Attribute. Methods with this attribute must be executed after the method containing the Setup Attribute.


Actions are not supported by Shelf Life Check. To automatically exit the application when the Shelf Life Check detects use beyond the expiration date, configure the ExpirationNotificationSinkElement to DefaultAction.

Supported .NET Application Types

Dotfuscator can inject Shelf Life code for all .NET assemblies except for the following:

See Also

Attribute Reference



© 2016 PreEmptive Solutions, LLC. All Rights Reserved.