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>

0 commit comments

Comments
 (0)