Skip to content

Commit 61056d0

Browse files
authored
Some .NET 9 maintenance and JSON encoder improvements (#2922)
- Reduce memory allocations in JSON encoder by using stackalloc/ArrayPool - Fix some new warnings in .NET9 code analyzers - Fix fuzzing error in JsonDecoder - do not use .NET9 libraries with .NET8 LTS builds #2931, #2940 - Bump langversion to 9 (max VS2019) - Use official ASP.Net 2.3. libraries for .NET Framework (rel. Jan 15th)
1 parent a0b12d7 commit 61056d0

File tree

51 files changed

+518
-245
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+518
-245
lines changed

Applications/Quickstarts.Servers/Alarms/AlarmHolders/ConditionTypeHolder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
* ======================================================================*/
2929

3030
using System;
31-
31+
using System.Globalization;
3232
using Opc.Ua;
3333

3434
#pragma warning disable CS1591
@@ -168,7 +168,7 @@ public void ReportEvent(ConditionState alarm = null)
168168
alarm.Time.Value = DateTime.UtcNow;
169169
alarm.ReceiveTime.Value = alarm.Time.Value;
170170

171-
Log("ReportEvent", " Value " + m_alarmController.GetValue().ToString() +
171+
Log("ReportEvent", " Value " + m_alarmController.GetValue().ToString(CultureInfo.InvariantCulture) +
172172
" Message " + alarm.Message.Value.Text);
173173

174174
alarm.ClearChangeMasks(SystemContext, true);

Applications/Quickstarts.Servers/Boiler/BoilerNodeManager.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
* http://opcfoundation.org/License/MIT/1.00/
2828
* ======================================================================*/
2929

30+
using System;
3031
using System.Collections.Generic;
3132
using System.Reflection;
3233
using Opc.Ua;

Applications/Quickstarts.Servers/ReferenceServer/ReferenceNodeManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1690,7 +1690,7 @@ private DataItemState[] CreateDataItemVariables(NodeState parent, string path, s
16901690
// now to create the remaining NUMBERED items
16911691
for (uint i = 0; i < numVariables; i++)
16921692
{
1693-
string newName = string.Format(CultureInfo.InvariantCulture, "{0}{1}", name, i.ToString("000"));
1693+
string newName = string.Format(CultureInfo.InvariantCulture, "{0}{1}", name, i.ToString("000", CultureInfo.InvariantCulture));
16941694
string newPath = string.Format(CultureInfo.InvariantCulture, "{0}/Mass/{1}", path, newName);
16951695
itemsCreated.Add(CreateDataItemVariable(parent, newPath, newName, dataType, valueRank));
16961696
}//for i

Applications/Quickstarts.Servers/TestData/TestDataObjectState.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
using System;
3131
using System.Collections.Generic;
32+
using System.Globalization;
3233
using Opc.Ua;
3334
using Range = Opc.Ua.Range;
3435

@@ -142,7 +143,7 @@ public ServiceResult OnWriteAnalogValue(
142143
element = ((Variant)element).Value;
143144
}
144145

145-
double elementNumber = Convert.ToDouble(element);
146+
double elementNumber = Convert.ToDouble(element, CultureInfo.InvariantCulture);
146147

147148
if (elementNumber > range.High || elementNumber < range.Low)
148149
{
@@ -153,7 +154,7 @@ public ServiceResult OnWriteAnalogValue(
153154
return ServiceResult.Good;
154155
}
155156

156-
double number = Convert.ToDouble(value);
157+
double number = Convert.ToDouble(value, CultureInfo.InvariantCulture);
157158

158159
if (number > range.High || number < range.Low)
159160
{

Fuzzing/Encoders/Fuzz.Tests/Opc.Ua.Encoders.Fuzz.Tests.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@
2020
<ItemGroup>
2121
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
2222
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
23-
<PackageReference Include="NUnit" Version="4.2.2" />
24-
<PackageReference Include="NUnit.Console" Version="3.18.3" />
23+
<PackageReference Include="NUnit" Version="4.3.2" />
24+
<PackageReference Include="NUnit.Console" Version="3.19.0" />
2525
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0">
2626
<PrivateAssets>all</PrivateAssets>
2727
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
2828
</PackageReference>
29-
<PackageReference Include="coverlet.collector" Version="6.0.2">
29+
<PackageReference Include="coverlet.collector" Version="6.0.3">
3030
<PrivateAssets>all</PrivateAssets>
3131
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
3232
</PackageReference>
33-
<PackageReference Include="SharpFuzz" Version="2.1.1" />
34-
<PackageReference Include="BenchmarkDotNet" Version="0.13.2" />
33+
<PackageReference Include="SharpFuzz" Version="2.2.0" />
34+
<PackageReference Include="BenchmarkDotNet" Version="0.13.12" />
3535
</ItemGroup>
3636

3737
<ItemGroup>

Libraries/Opc.Ua.Client.ComplexTypes/Opc.Ua.Client.ComplexTypes.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<AssemblyName>Opc.Ua.Client.ComplexTypes</AssemblyName>
4+
<AssemblyName>$(AssemblyPrefix).Client.ComplexTypes</AssemblyName>
55
<TargetFrameworks>$(LibxTargetFrameworks)</TargetFrameworks>
66
<PackageId>$(PackagePrefix).Opc.Ua.Client.ComplexTypes</PackageId>
77
<RootNameSpace>Opc.Ua.Client.ComplexTypes</RootNameSpace>

Libraries/Opc.Ua.Client/Opc.Ua.Client.csproj

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<DefineConstants>$(DefineConstants);CLIENT_ASYNC</DefineConstants>
5-
<AssemblyName>Opc.Ua.Client</AssemblyName>
5+
<AssemblyName>$(AssemblyPrefix).Client</AssemblyName>
66
<TargetFrameworks>$(LibTargetFrameworks)</TargetFrameworks>
77
<PackageId>$(PackagePrefix).Opc.Ua.Client</PackageId>
88
<RootNamespace>Opc.Ua.Client</RootNamespace>
@@ -21,10 +21,6 @@
2121
<PackageId>$(PackageId).Debug</PackageId>
2222
</PropertyGroup>
2323

24-
<ItemGroup Condition="'$(TargetFramework)' != 'net6.0' AND '$(TargetFramework)' != 'net7.0' AND '$(TargetFramework)' != 'net8.0'">
25-
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="6.0.1" />
26-
</ItemGroup>
27-
2824
<ItemGroup>
2925
<ProjectReference Include="..\..\Stack\Opc.Ua.Core\Opc.Ua.Core.csproj" />
3026
<ProjectReference Include="..\Opc.Ua.Configuration\Opc.Ua.Configuration.csproj" />

Libraries/Opc.Ua.Client/Session/Session.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6084,6 +6084,7 @@ private void ProcessPublishResponse(
60846084
// ignore messages with a subscription that has been deleted.
60856085
if (subscription != null)
60866086
{
6087+
#if DEBUG
60876088
// Validate publish time and reject old values.
60886089
if (notificationMessage.PublishTime.AddMilliseconds(subscription.CurrentPublishingInterval * subscription.CurrentLifetimeCount) < DateTime.UtcNow)
60896090
{
@@ -6095,12 +6096,15 @@ private void ProcessPublishResponse(
60956096
{
60966097
Utils.LogTrace("PublishTime {0} in publish response is newer than actual time for SubscriptionId {1}.", notificationMessage.PublishTime.ToLocalTime(), subscription.Id);
60976098
}
6099+
#endif
6100+
// save the information that more notifications are expected
6101+
notificationMessage.MoreNotifications = moreNotifications;
6102+
6103+
// save the string table that came with the notification.
6104+
notificationMessage.StringTable = responseHeader.StringTable;
60986105

60996106
// update subscription cache.
6100-
subscription.SaveMessageInCache(
6101-
availableSequenceNumbers,
6102-
notificationMessage,
6103-
responseHeader.StringTable);
6107+
subscription.SaveMessageInCache(availableSequenceNumbers, notificationMessage);
61046108

61056109
// raise the notification.
61066110
NotificationEventHandler publishEventHandler = m_Publish;

Libraries/Opc.Ua.Client/Subscription/Subscription.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,8 +1385,7 @@ public List<ServiceResult> SetMonitoringMode(
13851385
/// </summary>
13861386
public void SaveMessageInCache(
13871387
IList<uint> availableSequenceNumbers,
1388-
NotificationMessage message,
1389-
IList<string> stringTable)
1388+
NotificationMessage message)
13901389
{
13911390
PublishStateChangedEventHandler callback = null;
13921391

@@ -1411,12 +1410,10 @@ public void SaveMessageInCache(
14111410

14121411
DateTime now = DateTime.UtcNow;
14131412
Interlocked.Exchange(ref m_lastNotificationTime, now.Ticks);
1413+
14141414
int tickCount = HiResClock.TickCount;
14151415
m_lastNotificationTickCount = tickCount;
14161416

1417-
// save the string table that came with notification.
1418-
message.StringTable = new List<string>(stringTable);
1419-
14201417
// create queue for the first time.
14211418
if (m_incomingMessages == null)
14221419
{
@@ -1443,10 +1440,11 @@ public void SaveMessageInCache(
14431440

14441441
if (next != null && next.Value.SequenceNumber > entry.SequenceNumber + 1)
14451442
{
1446-
IncomingMessage placeholder = new IncomingMessage();
1447-
placeholder.SequenceNumber = entry.SequenceNumber + 1;
1448-
placeholder.Timestamp = now;
1449-
placeholder.TickCount = tickCount;
1443+
var placeholder = new IncomingMessage {
1444+
SequenceNumber = entry.SequenceNumber + 1,
1445+
Timestamp = now,
1446+
TickCount = tickCount
1447+
};
14501448
node = m_incomingMessages.AddAfter(node, placeholder);
14511449
continue;
14521450
}

Libraries/Opc.Ua.Configuration/Opc.Ua.Configuration.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<AssemblyName>Opc.Ua.Configuration</AssemblyName>
4+
<AssemblyName>$(AssemblyPrefix).Configuration</AssemblyName>
55
<TargetFrameworks>$(LibTargetFrameworks)</TargetFrameworks>
66
<PackageId>$(PackagePrefix).Opc.Ua.Configuration</PackageId>
77
<RootNamespace>Opc.Ua.Configuration</RootNamespace>

Libraries/Opc.Ua.Gds.Client.Common/Opc.Ua.Gds.Client.Common.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<AssemblyName>Opc.Ua.Gds.Client.Common</AssemblyName>
4+
<AssemblyName>$(AssemblyPrefix).Gds.Client.Common</AssemblyName>
55
<TargetFrameworks>$(LibTargetFrameworks)</TargetFrameworks>
66
<PackageId>$(PackagePrefix).Opc.Ua.Gds.Client.Common</PackageId>
77
<RootNamespace>Opc.Ua.Gds.Client</RootNamespace>

Libraries/Opc.Ua.Gds.Server.Common/Opc.Ua.Gds.Server.Common.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<AssemblyName>Opc.Ua.Gds.Server.Common</AssemblyName>
4+
<AssemblyName>$(AssemblyPrefix).Gds.Server.Common</AssemblyName>
55
<TargetFrameworks>$(LibTargetFrameworks)</TargetFrameworks>
66
<PackageId>$(PackagePrefix).Opc.Ua.Gds.Server.Common</PackageId>
77
<RootNamespace>Opc.Ua.Gds.Server</RootNamespace>

Libraries/Opc.Ua.PubSub/Opc.Ua.PubSub.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<AssemblyName>Opc.Ua.PubSub</AssemblyName>
4+
<AssemblyName>$(AssemblyPrefix).PubSub</AssemblyName>
55
<TargetFrameworks>$(LibxTargetFrameworks)</TargetFrameworks>
66
<PackageId>$(PackagePrefix).Opc.Ua.PubSub</PackageId>
77
<RootNamespace>Opc.Ua.PubSub</RootNamespace>

Libraries/Opc.Ua.Security.Certificates/Opc.Ua.Security.Certificates.csproj

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
32
<PropertyGroup>
4-
<AssemblyName>Opc.Ua.Security.Certificates</AssemblyName>
53
<TargetFrameworks>$(LibCoreTargetFrameworks)</TargetFrameworks>
64
<PackageId>$(PackagePrefix).Opc.Ua.Security.Certificates</PackageId>
5+
<AssemblyName>$(AssemblyPrefix).Security.Certificates</AssemblyName>
76
<RootNamespace>Opc.Ua.Security.Certificates</RootNamespace>
87
<Description>OPC UA Security X509 Certificates Class Library</Description>
98
<IsPackable>true</IsPackable>
@@ -15,6 +14,7 @@
1514
<GenerateDocumentationFile>true</GenerateDocumentationFile>
1615
</PropertyGroup>
1716

17+
<!-- Choose which platforms support ECC -->
1818
<Choose>
1919
<When Condition="'$(TargetFramework)' == 'net462'">
2020
<ItemGroup>
@@ -41,17 +41,25 @@
4141
<DefineConstants>$(DefineConstants);SIGNASSEMBLY</DefineConstants>
4242
</PropertyGroup>
4343

44-
<ItemGroup>
45-
<PackageReference Include="System.Formats.Asn1" Version="8.0.1" />
46-
</ItemGroup>
47-
48-
<ItemGroup Condition="'$(TargetFramework)' == 'net472'">
49-
<PackageReference Include="BouncyCastle.Cryptography" Version="2.5.0" />
50-
</ItemGroup>
51-
52-
<ItemGroup Condition="'$(TargetFramework)' == 'net48'">
53-
<PackageReference Include="BouncyCastle.Cryptography" Version="2.5.0" />
54-
</ItemGroup>
44+
<!-- Choose Asn1 encoder and additional crypto library version -->
45+
<Choose>
46+
<When Condition="'$(TargetFramework)' == 'net472' OR '$(TargetFramework)' == 'net48'">
47+
<ItemGroup>
48+
<PackageReference Include="BouncyCastle.Cryptography" Version="2.5.0" />
49+
<PackageReference Include="System.Formats.Asn1" Version="8.0.1" />
50+
</ItemGroup>
51+
</When>
52+
<When Condition="'$(TargetFramework)' == 'net9.0'">
53+
<ItemGroup>
54+
<PackageReference Include="System.Formats.Asn1" Version="9.0.1" />
55+
</ItemGroup>
56+
</When>
57+
<Otherwise>
58+
<ItemGroup>
59+
<PackageReference Include="System.Formats.Asn1" Version="8.0.1" />
60+
</ItemGroup>
61+
</Otherwise>
62+
</Choose>
5563

5664
<Target Name="GetPackagingOutputs" />
5765

Libraries/Opc.Ua.Server/Opc.Ua.Server.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<AssemblyName>Opc.Ua.Server</AssemblyName>
54
<TargetFrameworks>$(LibTargetFrameworks)</TargetFrameworks>
65
<PackageId>$(PackagePrefix).Opc.Ua.Server</PackageId>
6+
<AssemblyName>$(AssemblyPrefix).Server</AssemblyName>
77
<RootNamespace>Opc.Ua.Server</RootNamespace>
88
<Description>OPC UA Server Class Library</Description>
99
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>

Stack/Opc.Ua.Bindings.Https/Opc.Ua.Bindings.Https.csproj

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,11 @@
2222
<Choose>
2323
<When Condition="'$(TargetFramework)' == 'net462' OR '$(TargetFramework)' == 'net472' OR '$(TargetFramework)' == 'net48' OR '$(TargetFramework)' == 'netstandard2.0' OR '$(TargetFramework)' == 'netstandard2.1'">
2424
<ItemGroup>
25-
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.1.3" />
26-
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel.Core" Version="2.1.25" />
27-
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets" Version="2.1.40" />
28-
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel.Https" Version="2.1.3" />
29-
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.1.34" />
30-
<PackageReference Include="System.Io.Pipelines" Version="6.0.3" />
31-
<PackageReference Include="System.Text.Encodings.Web" Version="8.0.0" />
25+
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.3.0" />
26+
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel.Core" Version="2.3.0" />
27+
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets" Version="2.3.0" />
28+
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel.Https" Version="2.3.0" />
29+
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.3.0" />
3230
</ItemGroup>
3331
</When>
3432
<Otherwise>

Stack/Opc.Ua.Core/Opc.Ua.Core.csproj

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<DefineConstants>$(DefineConstants);NET_STANDARD;NET_STANDARD_ASYNC</DefineConstants>
55
<TargetFrameworks>$(LibCoreTargetFrameworks)</TargetFrameworks>
6-
<AssemblyName>Opc.Ua.Core</AssemblyName>
6+
<AssemblyName>$(AssemblyPrefix).Core</AssemblyName>
77
<PackageId>$(PackagePrefix).Opc.Ua.Core</PackageId>
88
<RootNamespace>Opc.Ua</RootNamespace>
99
<Description>OPC UA Core Class Library</Description>
@@ -45,7 +45,7 @@
4545
use latest versions only on .NET 5/6/7/8, otherwise 3.1.x -->
4646
<When Condition="'$(TargetFramework)' == 'netstandard2.0' OR '$(TargetFramework)' == 'netstandard2.1'">
4747
<ItemGroup>
48-
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="6.0.1" />
48+
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="6.0.2" />
4949
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.1.32" />
5050
</ItemGroup>
5151
</When>
@@ -54,15 +54,20 @@
5454
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.4" />
5555
</ItemGroup>
5656
</When>
57+
<When Condition="'$(TargetFramework)' == 'net8.0'">
58+
<ItemGroup>
59+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.2" />
60+
</ItemGroup>
61+
</When>
5762
<When Condition="'$(TargetFramework)' == 'net462' OR '$(TargetFramework)' == 'net472' OR '$(TargetFramework)' == 'net48'">
5863
<ItemGroup>
59-
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="6.0.1" />
64+
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="6.0.2" />
6065
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.4" />
6166
</ItemGroup>
6267
</When>
6368
<Otherwise>
6469
<ItemGroup>
65-
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.0" />
70+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.1" />
6671
</ItemGroup>
6772
</Otherwise>
6873
</Choose>

0 commit comments

Comments
 (0)