I had created a couple of years ago a C# client that changes several tags every minute or so; I had to update my computer and I updated to VS 2026, .NET 10.0 and I am using the latest version of the OPC Foundation C# library (1.5.378.65).
Apparently, there have been many changes regarding the async ways in which all functions are now implemented; but the main problem is that now I am not able to stablish no connection to Ignition OPC UA server.
I have disabled the Security Policies to “None” and I create the session with an Anonymous connection, but still when debugging I have a Connection Error: [80AE0000] 'Remote side closed connection'.
Here is the code for the configuration:
try
{
// 1. Discovery remains the same
using var discoveryClient = await DiscoveryClient.CreateAsync(new Uri(url), null);
var endpoints = await discoveryClient.GetEndpointsAsync(null);
try{
var discoveryClient = await DiscoveryClient.CreateAsync(new Uri(url), null);
var endpoints = await discoveryClient.GetEndpointsAsync(null);
var endpointDescription = SelectEndpoint(endpoints, false);
var endpoint = new ConfiguredEndpoint(null, endpointDescription, EndpointConfiguration.Create(config));
// 2. DIRECT SESSION CREATION (Fixes CS0246 & CS0120)
// We use the 8-parameter overload which is the modern non-obsolete standard
var session = await Session.Create(
config, // 1. ApplicationConfiguration
endpoint, // 2. ConfiguredEndpoint
false, // 4. bool checkDomain
"MachineSession", // 5. string sessionName
60000, // 6. uint sessionTimeout
new UserIdentity(new AnonymousIdentityToken()), // 7. IUserIdentity
null,
CancellationToken.None // 8. CancellationToken (MANDATORY)
);
Console.WriteLine("Connected!");
var rng = new Random();
while (true)
{
var val = new WriteValue
{
NodeId = nodeId,
AttributeId = Attributes.Value,
Value = new DataValue(new Variant((ushort)rng.Next(0, 100)))
};
// Use WriteAsync as required by modern standards
await session.WriteAsync(null, new WriteValueCollection { val }, CancellationToken.None);
await Task.Delay(2000);
}
}
catch (Exception ex) { Console.WriteLine($"Connection Error: {ex.Message}"); }