Using .NET Framework with the New RTI Connext C# API

In 2020, Microsoft released .NET 5 with the goal of unifying the .NET world and effectively deprecating .NET Framework, .NET Core, and .NET Standard (in technical terms, .NET 5 is the evolution of .NET Core 3.1).

Taking this into account, the documentation for the new RTI Connext C# API released in RTI Connext 6.1 and the API's out-of-the-box experience favor the use of .NET 5. Nonetheless, the RTI Connext C# API is built to work on any .NET Standard 2.0-based platform, which includes the latest .NET Framework versions starting from 4.6.1 (see .NET Standard).

If you are not yet ready to port your legacy .NET Framework applications to .NET 5, but want to keep using Connext DDS, there are some considerations to take into account, depending on your environment.

Using the RTI Connext C# API in .NET Framework applications with Visual Studio 2019

Depending on whether you want to create an example from scratch or configure an existing .NET Framework project, there may be two different approaches.

A) Create an application from scratch using RTI Code Generator

First, we will need to generate code for .NET Core 2.1 with rtiddsgen.

rtiddsgen -language c# Foo.idl -example netcoreapp2.1

You will find a C# project file Foo.csproj has been generated. This file configures how to build and run your C# application. We need to modify it in order to target our .NET Framework version. For example:

<TargetFramework>net47</TargetFramework>

Now we are ready to build the project using VS 2019.

B) Configure an existing .NET Framework project

These are the steps to add the RTI Connext DDS package to an existing .NET Framework project.

1.- Configure your NuGet source so it can find the necessary NuGet packages from your Connext DDS installation:

dotnet nuget add source <NDDSHOME>/lib/dotnet -n RTI

*Note: you can also develop your application using the NuGet packages from nuget.org. This is described in section 2.5. “Developing with the nuget.org package” from our Getting Started Guide for C#.

2.- Add the Rti.ConnextDds package into your project. For example, if you have a C# project in /home/user/my_project/MyProj.csproj:

cd /home/user/my_project
dotnet add package Rti.ConnextDds

If you have more C# projects, repeat this step for each additional project.

3.- Generate the C# code for your IDL types using RTI Code Generator:

rtiddsgen -language c# Foo.idl -d /home/user/my_project

Now you are ready to build your application.

Using the RTI Connext C# API in .NET Framework applications with Visual Studio 2017

Additional configuration settings are necessary for developing a .NET Framework project using the RTI Connext C# API in Visual Studio 2017. For the sake of simplicity, we will use a brand new Visual Studio project and a generated Connext DDS example as the baseline to demonstrate how to configure the environment.

1.- First let’s create a new .NET Framework project in Visual Studio 2017. You can do this in Visual Studio 2017 under File>new project>get started>Console app. Make sure you select the Framework version you want to use (e.g., 4.7).

2.- Add the Package Source for the Rti.ConnextDds NuGet package that is available in the RTI Connext installation. To do so, open the "solution explorer" in Visual Studio, right-click in “References” and then “manage NuGet packages”. Within the Nuget Package Manager, click on the Settings button (gear icon next to the “package source:”). There, add a new Package Source pointing to your Connext DDS .NET libraries. For example: C:\Program Files\rti_connext_dds-6.1.0\lib\dotnet.

3.- Open again the Nuget Package Manager and install the Rti.ConnextDds from the newly created “package source”. Once this is done, you will see a reference to Rti.ConnextDds within the “Solution explorer” dropdown list.

4.- To avoid compilation issues such as undefined references, it is necessary to add a reference to the NETStandard.Library 2.0.0 NuGet package. To do this, use the NuGet Package Manager to install the “NETStandard.Library 2.0.0” package. Then, within the “Solution Explorer,” right-click in the project name (e.g., “my_project”) to “unload project” and again to “edit *.csproj file” so you can add a new reference to this package within the project:
 <Reference Include="netstandard"/>

Once this is done, click on “reload project” to apply the changes.

5.- Modify the C# language version to C# 7.3 in order to avoid compilation issues related to “non-trailing named arguments”. This can be done under Project -> <appname> properties -> build -> advanced by setting the “language version” to at least “c# 7.3”.

Note: C# 7.3 support was introduced in Visual Studio 2017 version 15.7. If you have an older version, you need to upgrade your Visual Studio first.

6.- Install the “System.CommandLine” NuGet package version "2.0.0-beta1.21308.1" using the NuGet Package Manager to avoid undefined references to “System.Commandline”. This step is necessary because the file FooProgram (generated in step 8) uses the CommandLine utility to parse the example application arguments. For more information on why version "2.0.0-beta1.21308.1" is needed please review this article from our Knowledge Base. You can skip this step if you intend to replace FooProgram.cs with your own code.

7.- Add the location path for the Rti.ConnextDds native libraries to your PATH environment variable. For example:

"<your_project>/Rti.ConnextDds.Native.6.1.0/runtimes/win-x64/native"

8.- Now that the environment is configured, generate the type files for your datatypes using RTI Code Generator:

rtiddsgen -language c# Foo.idl -example netcoreapp2.1

Add the generated .cs files into the project. For example:

Foo.cs
FooPlugin.cs
FooProgram.cs
FooSubscriber.cs
FooPublisher.cs    

You can now build the project.

Platform:
Programming Language: