VB.NET SDK
VB.NET apps use the same LicenPro.SDK NuGet package as C#: the same classes, the same license files and the same behavior. This page shows the common tasks in VB syntax. Everything on the other .NET SDK pages applies to VB unchanged.
Install LicenPro.SDK from NuGet. It ships net8.0 and net9.0 builds, so the VB.NET project must target .NET 8 or later. Projects on .NET Framework, VB6 and VBA cannot use it.
dotnet add package LicenPro.SDK
1. Startup
Call SdkBootstrap.OnApplicationStartup() first in Sub Main, before any form is shown. It loads licenpro.settings.json and installs a downloaded update (the app then restarts as the new version).
If your project uses the VB application framework instead of Sub Main, call it in the Startup event in ApplicationEvents.vb.
Imports LicenPro.SDK.AppHosting
Friend Module Program
<STAThread()>
Friend Sub Main(args As String())
' First line: loads licenpro.settings.json and installs a downloaded update (then exits and restarts).
SdkBootstrap.OnApplicationStartup()
Application.SetHighDpiMode(HighDpiMode.SystemAware)
Application.EnableVisualStyles()
Application.SetCompatibleTextRenderingDefault(False)
Application.Run(New MainForm())
End Sub
End Module
2. Validate in the main form
Keep one LicenseClient for the life of the app. Create it on the UI thread, for example in Shown: its events are then raised on the UI thread, so the handlers can update controls directly.
Await ValidateAsync() keeps the window responsive while it checks the signed file, the server, the activation and the session (when the license needs them).
Imports LicenPro.SDK
Imports LicenPro.SDK.AppHosting
Public Class MainForm
' Your product public key (Base64, without PEM headers).
Private Const PublicKeyBase64 As String = "MIIBCgKCAQEA..."
Private _licenseClient As LicenseClient
Private Async Sub MainForm_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
' Created on the UI thread, so the client's events also arrive on the UI thread.
_licenseClient = New LicenseClient(New LicenseClientOptions With {
.LicenseFilePath = "C:\ProgramData\MyApp\license.bin",
.PublicKey = PublicKeyBase64,
.LicenseKey = txtLicenseKey.Text
})
AddHandler _licenseClient.LicenseExpiringSoon, AddressOf OnLicenseExpiringSoon
AddHandler _licenseClient.SessionDisconnected, AddressOf OnSessionDisconnected
Dim result = Await _licenseClient.ValidateAsync()
If result.IsValid Then
lblStatus.Text = $"Licensed ({result.License.Type})"
btnExport.Enabled = FeatureManager.IsFeatureEnabled("Premium")
Else
Dim feedback = LicenseValidationFeedback.From(result)
MessageBox.Show(feedback.DialogMessage, feedback.DialogTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
End Sub
Private Sub OnLicenseExpiringSoon(sender As Object, e As LicenseExpiryNoticeEventArgs)
MessageBox.Show(e.Notice.Message, e.Notice.Title)
End Sub
Private Sub OnSessionDisconnected(sender As Object, reason As String)
lblStatus.Text = $"License session ended: {reason}"
End Sub
Private Sub MainForm_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
' Ends the license session. Safe on the UI thread.
_licenseClient?.Dispose()
End Sub
End Class
Dispose() and Using need a package newer than 1.8.7
LicenseClient implements IDisposable from the next LicenPro.SDK release. Version 1.8.7, the latest on NuGet today, only has DisposeAsync(): use the code in section 5 with it.
A refused license is a result, not an exception: check result.IsValid and result.Status. LicenseValidationFeedback.From(result) turns a refusal into a title and message for a dialog.
For a license that is allowed offline, ValidateOfflineAsync() checks the signed file without calling the server. Validate() and ValidateOffline() are synchronous versions for console apps; in a form they would freeze the window until the server answers.
3. Features
FeatureManager reads the features of the license that was validated last.
' After a successful validation; each call reads the validated license.
Dim premium As Boolean = FeatureManager.IsFeatureEnabled("Premium")
Dim maxUsers As Integer = FeatureManager.GetFeatureInt("MaxUsers") ' 0 when missing
Dim edition As String = FeatureManager.GetFeatureString("Edition") ' Nothing when missing
4. Events
Subscribe with AddHandler, as in the main form above:
LicenseExpiringSoon: a subscription ends withinSubscriptionExpiryWarningDays(default 7; setIncludeTrialInExpiryWarningsto include trials).e.NoticehasTitle,MessageandWholeDaysRemaining.SessionDisconnected: a heartbeat reported the license invalid (its features are then disabled), a reconnect failed, or the server missed 3 heartbeats in a row (reasonUnreachable; the license stays loaded and the SDK keeps retrying). TheStringargument is the reason.
5. Ending the license session
Disposing the client tells the server that the session ended, so a Floating or Concurrent seat is released at once instead of after missed heartbeats.
Newer than 1.8.7: Dispose and Using
In a form, call Dispose() in FormClosing, as above. It is safe on the UI thread, and calling it again does nothing.
For a short check, such as a console tool, a Using block ends the session at End Using:
Imports LicenPro.SDK
Module Program
Sub Main()
Dim options As New LicenseClientOptions With {
.LicenseFilePath = "license.bin",
.PublicKey = "MIIBCgKCAQEA...",
.LicenseKey = "XXXX-XXXX-XXXX-XXXX"
}
Using client As New LicenseClient(options)
Dim result = client.Validate()
If result.IsValid Then
Console.WriteLine($"Licensed: {result.License.LicenseKey}")
Else
Console.WriteLine($"{result.ErrorTitle}: {result.ErrorMessage}")
End If
End Using ' ends the license session
End Sub
End Module
1.8.7 and earlier: DisposeAsync
These versions only implement IAsyncDisposable, so Using does not compile (error BC36010), and VB cannot Await inside Finally.
Call Await client.DisposeAsync() after the Try block instead:
Imports LicenPro.Exceptions
Imports LicenPro.SDK
Friend Module LicenseCheck
Public Async Function CheckLicenseAsync(options As LicenseClientOptions) As Task(Of String)
Dim client As New LicenseClient(options)
Dim outcome As String
Try
Dim result = Await client.ValidateAsync()
outcome = If(result.IsValid, "Licensed", result.ErrorMessage)
Catch ex As LicenseException
outcome = ex.Message
End Try
' VB cannot Await inside Finally, so the session ends after the Try block.
Await client.DisposeAsync()
Return outcome
End Function
End Module
In a form, keep the window open until the session has ended:
Private Async Sub MainForm_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
If _licenseClient Is Nothing Then Return
e.Cancel = True ' keep the form open until the session has ended
Dim client = _licenseClient
_licenseClient = Nothing
Await client.DisposeAsync()
Close() ' runs this handler again, now with no client
End Sub
6. Reading the C# pages in VB
The other SDK pages show C#. These are the constructs that change:
| C# | VB.NET |
|---|---|
new LicenseClientOptions { LicenseKey = key } | New LicenseClientOptions With {.LicenseKey = key} |
client.LicenseExpiringSoon += OnExpiring; | AddHandler client.LicenseExpiringSoon, AddressOf OnExpiring |
await client.ValidateAsync() | Await client.ValidateAsync() inside an Async Sub or Async Function |
using var client = new LicenseClient(options); | Using client As New LicenseClient(options) … End Using (newer than 1.8.7) |
await client.DisposeAsync(); in finally | Await client.DisposeAsync() after End Try |
ConsumeMeterWithRetryAsync("Export", requestId, quantity: 2) | ConsumeMeterWithRetryAsync("Export", requestId, quantity:=2) |
if (client is not null) | If client IsNot Nothing Then |
