Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

AF SDK Reference

.NET 4.5 Differences

  • Last UpdatedNov 18, 2025
  • 8 minute read
.NET 4.5 Differences

Beginning in AF 2.5 (2012), the AF SDK shipped with both a .NET 3.5 version and .NET 4 assembly. The .NET 4 version of the AF SDK contains support for enhanced data access calls for all attributes. Data access to PI data from the .NET 4 version of the AF SDK does not use PI SDK to access the PI Data Archive server. This topic identifies the differences between the .NET 3.5 and .NET 4 versions of the AF SDK Library. If you are using .NET 3.5, please see What's New in PI AF 2018 SP3 Patch 2.

This topic contains the following sections:

Referencing the AF SDK in Visual Studio

Your Visual Studio Project must reference the proper version of the AF SDK. If your project targets .NET 3.5, you will only be able to reference the .NET 3.5 version of the AF SDK assembly (located in %PIHOME%\AF\PublicAssemblies, Assembly Version 2.0.0.0), and you will not have access to the enhanced data capabilities. If your project targets .NET 4 or later, you should reference the .NET 4 version of the AF SDK. The .NET 4 version of the AF SDK has an Assembly version of 4.0.0.0 and is located in the directory %PIHOME%\AF\PublicAssemblies\4.0. Please note that there is often a considerable delay in the Visual Studio Add Reference Dialog before it adds the .NET 4 version of the AF SDK in the list of assemblies .in the NET tab.

Back to the Top

Which Version will be Loaded

The version of the AF SDK that is loaded is determined by the .NET version used by the application. All .NET 3.5 executables will use the .NET 3.5 version of the AF SDK and will not have access to the new features in the .NET 4 version of the AF SDK. Any .NET 4 executable will automatically utilize the newer .NET 4 AF SDK regardless of which version it was linked against. In order to have access to the new features in the .NET 4 version of the AF SDK, the application must be compiled with a reference to the .NET 4 version of the AF SDK.

A .NET 4 executable which was linked against a .NET 3.5 version of the AF SDK can be forced to use the .NET 3.5 version of the AF SDK and UI controls by adding the following lines to its configuration file:

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="OSIsoft.AFSDK" publicKeyToken="6238BE57836698E6" />
        <publisherPolicy apply="no" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="OSIsoft.AF.UI" publicKeyToken="6238BE57836698E6" />
        <publisherPolicy apply="no" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

Back to the Top

PI SDK Hybrid Application

A hybrid application is an application that uses both the PI SDK and the .NET 4 version of the AF SDK to access data on the PI Data Archive server. Note that the connection to the PI Data Archive server using the PI SDK is different than the connection used by the AF SDK. For example, if an explicit login is used, it will need to be made in both the PI SDK Server object and AF SDK PIServer object.

Back to the Top

Data Behavior Differences

There are some behavior changes between the .NET 3.5 and .NET 4 versions of the AF SDK. The .NET 4 version of the AF SDK does not return PI SDK objects, such as PIDigitalState and PITime, in data value calls.

Tag Lookup

AF Attributes configured with a PI Point Data Reference use a different algorithm in the two different versions to resolve the tag path. The configuration string of a PI Point normally contains a server name, server id, tag name and tag id. The id's are not shown in PI System Explorer but can be seen in an XML export. The id's are not present in all cases, for example, if the tag path was built by substitution parameters from the template, the id's will not be present until a create/update configuration is executed on the attribute or containing element.

Both versions of the PI Point Data Reference will use the server id first to look up the PI Data Archive server and fall back to the name only if the server is not found. The .NET 3.5 PI Point Data Reference will use the tag name first to look up the tag, then, fall back to use the tag id if no tag is found. The .NET 4 PI Point Data Reference will use the tag id first, and only use the name if the tag id is found to be missing on the PI Data Archive. Both versions of the PI Point Data Reference will only use the tag id if the server id matches. The change in the behavior in the .NET 4 version was made to allow the data reference to initialize itself much more quickly as the tag does not need to be resolved prior to its use.

Digital States

System Digital States from the PI Data Archive are now returned as AFEnumerationValue from the SystemStateSet. For example, when no data was available at the requested time, the .NET 3.5 AF SDK will return a "No Data" Digital State value. The .NET 4 AF SDK will return the NoData system enumeration value. As in previous releases, Non-System Digital States will be converted into the type specified in the associated attribute. However, if the attribute does not have a data specified (shown as <Anything> in PI System Explorer), the type returned will be AFEnumerationValue. In this case, the enumeration value will have a null value for the EnumerationSet property.

Errors Returned from the PI Data Archive

Errors returned from the PI Data Archive in the .NET 3.5 AF SDK are returned as an InvalidOperationException. Errors returned from the PI Data Archive in the .NET 4 AF SDK are returned as a PIException or PIConnectionException.

AFAttribute.RawPIPoint

Both the .NET 3.5 and .NET 4 version of the AF SDK will return a PISDK.PIPoint object. However, in the .NET 4 version of the AF SDK, this property will not be cached and will be re-instantiated with each call. Note that the .NET 4 version of the AF SDK does not use the PI SDK and thus retrieving the PISDK.PIPoint object in this manner will require a separate PI SDK connection to the PI Data Archive server. Applications using the .NET 4 version of the AF SDK should use the new PIPoint property which returns a PIPoint defined by the AF SDK.

PI Collective Behaviors

There are differences between how the PI SDK and AF SDK work with PI Data Archive collectives. Like PI SDK, AF SDK allows you to connect to a PI Data Archive collective (the default behavior), or, by utilizing the PICollectiveMemberConnect and PICollectiveMemberConnectDirect methods, you can connect directly to a specific member of the collective. The type of connection, collective or member specific, will determine the behavior of your application in regard to fail over, and allowed operations. These differences are detailed below. Most user-based applications should connect to the collective and not to individual members.

Data (Event) Writes

Both .NET 4 AF SDK and .NET 3.5 AF SDK support buffering via the PI Buffer Subsystem. When writing PI Point events to PI Collectives, buffering is the preferred mechanism to ensure consistent data delivery. If not buffering, the .NET 4 AF SDK will write only to the currently connected member, regardless of whether the connected member is a primary or secondary. If the PI Member Server has the Replication_EnableSDKWriteValues flag set to 0 (the default setting), then writes from the .NET 4 AF SDK will fail unless the application has connected directly to the member via PICollectiveMemberConnect or PICollectiveMemberConnectDirect. The setting of the flag for the currently connected member can be read via the PICollective.AllowWriteValues property. The .NET 3.5 AF SDK utilizes the PI SDK and will automatically fail over to the primary if the Replication_EnableSDKWriteValues flag set to 0 when connected to the PI Data Archive collective.

Configuration Changes

Writing configuration changes to a PI Collective, such as creating PI Points or setting Point Attributes, is only supported on the primary member. When connected to a collective secondary, the PI SDK's behavior is to automatically fail over to the primary when a configuration change operations is attempted. Writing configuration changes via the .NET 4 AF SDK, AF's behavior is to automatically create a connection to the primary for the operation, but leave the open connection to the secondary in place. This prevents inadvertent fail over for other operations. Like PI SDK, fail over for configuration change operations will not occur in the .NET 4 AF SDK if you have made a specific direct connection to a secondary member.

Failover

When an application using the .NET 4 AF SDK is attached to a collective, and the connection is lost to the current member due to network failure, server failure, or server shutdown, the AF SDK will attempt a reconnection to another member. The .NET 4 AF SDK behaves identically to PI SDK in this regard, utilizing the priority setting defined for the collective members to determine the order of connection attempts. If the original connection was made with the AFConnectionPreference of RequirePrimary, then no fail over will occur.

.NET 4 Only Features

Methods, properties, and classes that are not available in the legacy .NET 3.5 version of the AF SDK are marked in the documentation with a note in the remark section: "This method, property, or class is not available in the legacy .NET 3.5 version of the SDK."

Back to the Top

Additional PI Namespace

Two additional namespaces are included in the .NET 4 version of the AF SDK: OSIsoft.AF.Data and OSIsoft.AF.PI. These namespaces provide the "Rich Data Access" features of the AF SDK.

Back to the Top

See Also

Other Resources

In This Topic
Related Links
TitleResults for “How to create a CRG?”Also Available in