diff --git a/.github/workflows/build-test.yaml b/.github/workflows/build-test.yaml
index e6d1eb194a..9d5814e3b2 100644
--- a/.github/workflows/build-test.yaml
+++ b/.github/workflows/build-test.yaml
@@ -20,9 +20,9 @@ jobs:
path: |
~/.nuget/packages
~/AppData/Local/NuGet/v3-cache
- key: ${{ runner.os }}-v1-nuget-${{ hashFiles('**/*.csproj') }}
+ key: ${{ runner.os }}-v2-nuget-${{ hashFiles('**/*.csproj','projects/Directory.Packages.props') }}
restore-keys: |
- ${{ runner.os }}-v1-nuget-
+ ${{ runner.os }}-v2-nuget-
- name: Build (Debug)
run: dotnet build ${{ github.workspace }}\Build.csproj
- name: Verify
@@ -142,9 +142,9 @@ jobs:
path: |
~/.nuget/packages
~/.local/share/NuGet/v3-cache
- key: ${{ runner.os }}-v1-nuget-${{ hashFiles('**/*.csproj') }}
+ key: ${{ runner.os }}-v2-nuget-${{ hashFiles('**/*.csproj','projects/Directory.Packages.props') }}
restore-keys: |
- ${{ runner.os }}-v1-nuget-
+ ${{ runner.os }}-v2-nuget-
- name: Build (Debug)
run: dotnet build ${{ github.workspace }}/Build.csproj
- name: Verify
diff --git a/projects/Directory.Packages.props b/projects/Directory.Packages.props
index 2a5f3a6ce1..22f9950bed 100644
--- a/projects/Directory.Packages.props
+++ b/projects/Directory.Packages.props
@@ -16,6 +16,8 @@
-->
+
+
@@ -33,13 +35,9 @@
-
-
-
-
diff --git a/projects/RabbitMQ.Client.OAuth2/CredentialsRefresherEventSource.cs b/projects/RabbitMQ.Client.OAuth2/CredentialsRefresherEventSource.cs
index b9d6707941..9db7beb3bd 100644
--- a/projects/RabbitMQ.Client.OAuth2/CredentialsRefresherEventSource.cs
+++ b/projects/RabbitMQ.Client.OAuth2/CredentialsRefresherEventSource.cs
@@ -46,7 +46,7 @@ public class CredentialsRefresherEventSource : EventSource
public void Stopped(string name) => WriteEvent(2, "Stopped", name);
[Event(3)]
-#if NET6_0_OR_GREATER
+#if NET
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "Parameters to this method are primitive and are trimmer safe")]
#endif
public void RefreshedCredentials(string name) => WriteEvent(3, "RefreshedCredentials", name);
diff --git a/projects/RabbitMQ.Client/DefaultEndpointResolver.cs b/projects/RabbitMQ.Client/DefaultEndpointResolver.cs
index 7da6b103e0..27368b1249 100644
--- a/projects/RabbitMQ.Client/DefaultEndpointResolver.cs
+++ b/projects/RabbitMQ.Client/DefaultEndpointResolver.cs
@@ -37,7 +37,7 @@ namespace RabbitMQ.Client
{
public class DefaultEndpointResolver : IEndpointResolver
{
-#if !NET6_0_OR_GREATER
+#if !NET
private readonly Random s_rnd = new Random();
#endif
private readonly List _endpoints;
@@ -49,7 +49,7 @@ public DefaultEndpointResolver(IEnumerable tcpEndpoints)
public IEnumerable All()
{
-#if NET6_0_OR_GREATER
+#if NET
return _endpoints.OrderBy(item => Random.Shared.Next());
#else
return _endpoints.OrderBy(item => s_rnd.Next());
diff --git a/projects/RabbitMQ.Client/Impl/AsyncManualResetEvent.cs b/projects/RabbitMQ.Client/Impl/AsyncManualResetEvent.cs
index d2394afb6a..58503d9981 100644
--- a/projects/RabbitMQ.Client/Impl/AsyncManualResetEvent.cs
+++ b/projects/RabbitMQ.Client/Impl/AsyncManualResetEvent.cs
@@ -64,7 +64,7 @@ public async ValueTask WaitAsync(CancellationToken cancellationToken)
cancellationToken.ThrowIfCancellationRequested();
CancellationTokenRegistration tokenRegistration =
-#if NET6_0_OR_GREATER
+#if NET
cancellationToken.UnsafeRegister(
static state =>
{
@@ -87,7 +87,7 @@ public async ValueTask WaitAsync(CancellationToken cancellationToken)
}
finally
{
-#if NET6_0_OR_GREATER
+#if NET
await tokenRegistration.DisposeAsync()
.ConfigureAwait(false);
#else
diff --git a/projects/RabbitMQ.Client/Impl/AsyncRpcContinuations.cs b/projects/RabbitMQ.Client/Impl/AsyncRpcContinuations.cs
index 6c57555cfc..1e0068a48c 100644
--- a/projects/RabbitMQ.Client/Impl/AsyncRpcContinuations.cs
+++ b/projects/RabbitMQ.Client/Impl/AsyncRpcContinuations.cs
@@ -60,7 +60,7 @@ public AsyncRpcContinuation(TimeSpan continuationTimeout, CancellationToken canc
*/
_continuationTimeoutCancellationTokenSource = new CancellationTokenSource(continuationTimeout);
-#if NET6_0_OR_GREATER
+#if NET
_continuationTimeoutCancellationTokenRegistration = _continuationTimeoutCancellationTokenSource.Token.UnsafeRegister((object? state) =>
{
var tcs = (TaskCompletionSource)state!;
diff --git a/projects/RabbitMQ.Client/Impl/Connection.Commands.cs b/projects/RabbitMQ.Client/Impl/Connection.Commands.cs
index 259746e44c..2b9f114120 100644
--- a/projects/RabbitMQ.Client/Impl/Connection.Commands.cs
+++ b/projects/RabbitMQ.Client/Impl/Connection.Commands.cs
@@ -76,7 +76,7 @@ private async ValueTask StartAndTuneAsync(CancellationToken cancellationToken)
{
var connectionStartCell = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
-#if NET6_0_OR_GREATER
+#if NET
using CancellationTokenRegistration ctr = cancellationToken.UnsafeRegister((object? state) =>
{
if (state != null)
@@ -197,7 +197,7 @@ private IAuthMechanismFactory GetAuthMechanismFactory(string supportedMechanismN
// Our list is in order of preference, the server one is not.
foreach (IAuthMechanismFactory factory in _config.AuthMechanisms)
{
-#if NET6_0_OR_GREATER
+#if NET
if (supportedMechanismNames.Contains(factory.Name, StringComparison.OrdinalIgnoreCase))
#else
if (supportedMechanismNames.IndexOf(factory.Name, StringComparison.OrdinalIgnoreCase) >= 0)
diff --git a/projects/RabbitMQ.Client/Impl/RecordedBinding.cs b/projects/RabbitMQ.Client/Impl/RecordedBinding.cs
index 1b9ac5717a..684f33200d 100644
--- a/projects/RabbitMQ.Client/Impl/RecordedBinding.cs
+++ b/projects/RabbitMQ.Client/Impl/RecordedBinding.cs
@@ -106,7 +106,7 @@ public override bool Equals(object? obj)
public override int GetHashCode()
{
-#if NET6_0_OR_GREATER
+#if NET
return HashCode.Combine(_isQueueBinding, _destination, _source, _routingKey, _arguments);
#else
unchecked
diff --git a/projects/RabbitMQ.Client/Impl/SocketFactory.cs b/projects/RabbitMQ.Client/Impl/SocketFactory.cs
index dd0773b99e..fcfffe82a3 100644
--- a/projects/RabbitMQ.Client/Impl/SocketFactory.cs
+++ b/projects/RabbitMQ.Client/Impl/SocketFactory.cs
@@ -45,7 +45,7 @@ public static async Task OpenAsync(AmqpTcpEndpoint amqpTcpEndpoint,
{
IPAddress[] ipAddresses = await Dns.GetHostAddressesAsync(
amqpTcpEndpoint.HostName
-#if NET6_0_OR_GREATER
+#if NET
, cancellationToken
#endif
).ConfigureAwait(false);
diff --git a/projects/RabbitMQ.Client/Impl/SslHelper.cs b/projects/RabbitMQ.Client/Impl/SslHelper.cs
index 68989de0c9..9eaca2b6cd 100644
--- a/projects/RabbitMQ.Client/Impl/SslHelper.cs
+++ b/projects/RabbitMQ.Client/Impl/SslHelper.cs
@@ -68,7 +68,7 @@ public static async Task TcpUpgradeAsync(Stream tcpStream, SslOption opt
Task TryAuthenticating(SslOption opts)
{
-#if NET6_0_OR_GREATER
+#if NET
X509RevocationMode certificateRevocationCheckMode = X509RevocationMode.NoCheck;
if (opts.CheckCertificateRevocation)
{
diff --git a/projects/RabbitMQ.Client/Impl/WireFormatting.Read.cs b/projects/RabbitMQ.Client/Impl/WireFormatting.Read.cs
index 4698369579..859968ff60 100644
--- a/projects/RabbitMQ.Client/Impl/WireFormatting.Read.cs
+++ b/projects/RabbitMQ.Client/Impl/WireFormatting.Read.cs
@@ -172,7 +172,7 @@ public static int ReadShortstr(ReadOnlySpan span, out string value)
// equals span.Length >= byteCount + 1
if (span.Length > byteCount)
{
-#if NETCOREAPP
+#if NET
value = UTF8.GetString(span.Slice(1, byteCount));
#else
unsafe
diff --git a/projects/RabbitMQ.Client/Impl/WireFormatting.Write.cs b/projects/RabbitMQ.Client/Impl/WireFormatting.Write.cs
index 97002edf43..77712d18d9 100644
--- a/projects/RabbitMQ.Client/Impl/WireFormatting.Write.cs
+++ b/projects/RabbitMQ.Client/Impl/WireFormatting.Write.cs
@@ -86,7 +86,7 @@ public static int GetArrayByteCount(IList? val)
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
-#if NETCOREAPP
+#if NET
public static int GetByteCount(ReadOnlySpan val) => val.IsEmpty ? 0 : UTF8.GetByteCount(val);
#else
public static int GetByteCount(string val) => string.IsNullOrEmpty(val) ? 0 : UTF8.GetByteCount(val);
diff --git a/projects/RabbitMQ.Client/Logging/RabbitMqClientEventSource.cs b/projects/RabbitMQ.Client/Logging/RabbitMqClientEventSource.cs
index 9f9b06cef2..87b628acb7 100644
--- a/projects/RabbitMQ.Client/Logging/RabbitMqClientEventSource.cs
+++ b/projects/RabbitMQ.Client/Logging/RabbitMqClientEventSource.cs
@@ -40,7 +40,7 @@ internal sealed partial class RabbitMqClientEventSource : EventSource
{
public static readonly RabbitMqClientEventSource Log = new RabbitMqClientEventSource();
-#if NET6_0_OR_GREATER
+#if NET
private readonly PollingCounter _connectionOpenedCounter;
private readonly PollingCounter _openConnectionCounter;
private readonly PollingCounter _channelOpenedCounter;
@@ -54,7 +54,7 @@ internal sealed partial class RabbitMqClientEventSource : EventSource
public RabbitMqClientEventSource()
: base("rabbitmq-client")
{
-#if NET6_0_OR_GREATER
+#if NET
_connectionOpenedCounter = new PollingCounter("total-connections-opened", this, () => s_connectionsOpened)
{
DisplayName = "Total connections opened"
@@ -128,7 +128,7 @@ public void Warn(string message)
}
}
-#if NET6_0_OR_GREATER
+#if NET
[Event(3, Keywords = Keywords.Log, Level = EventLevel.Error)]
[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "The properties are preserved with the DynamicallyAccessedMembers attribute.")]
public void Error(string message, RabbitMqExceptionDetail ex)
diff --git a/projects/RabbitMQ.Client/TaskExtensions.cs b/projects/RabbitMQ.Client/TaskExtensions.cs
index 1d28ac2c49..458957217d 100644
--- a/projects/RabbitMQ.Client/TaskExtensions.cs
+++ b/projects/RabbitMQ.Client/TaskExtensions.cs
@@ -37,7 +37,7 @@ namespace RabbitMQ.Client
{
internal static class TaskExtensions
{
-#if NET6_0_OR_GREATER
+#if NET
public static bool IsCompletedSuccessfully(this Task task)
{
return task.IsCompletedSuccessfully;
@@ -49,7 +49,7 @@ public static bool IsCompletedSuccessfully(this Task task)
}
#endif
-#if !NET6_0_OR_GREATER
+#if !NET
private static readonly TaskContinuationOptions s_tco = TaskContinuationOptions.OnlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously;
private static void IgnoreTaskContinuation(Task t, object s) => t.Exception.Handle(e => true);
@@ -126,7 +126,7 @@ private static async Task DoWaitAsync(this Task task, CancellationToken cancella
public static Task WaitAsync(this Task task, TimeSpan timeout)
{
-#if NET6_0_OR_GREATER
+#if NET
if (task.IsCompletedSuccessfully)
{
return task;
@@ -171,7 +171,7 @@ public static async ValueTask TimeoutAfter(this ValueTask valueTask, TimeSpan ti
return;
}
-#if NET6_0_OR_GREATER
+#if NET
Task task = valueTask.AsTask();
await task.WaitAsync(timeout)
.ConfigureAwait(false);
diff --git a/projects/RabbitMQ.Client/TcpClientAdapter.cs b/projects/RabbitMQ.Client/TcpClientAdapter.cs
index 4a36b4ad8e..73a9856253 100644
--- a/projects/RabbitMQ.Client/TcpClientAdapter.cs
+++ b/projects/RabbitMQ.Client/TcpClientAdapter.cs
@@ -20,7 +20,7 @@ public TcpClientAdapter(Socket socket)
_sock = socket ?? throw new InvalidOperationException("socket must not be null");
}
-#if NET6_0_OR_GREATER
+#if NET
public virtual Task ConnectAsync(IPAddress ep, int port, CancellationToken cancellationToken = default)
{
return _sock.ConnectAsync(ep, port, cancellationToken).AsTask();
diff --git a/projects/Test/Common/Common.csproj b/projects/Test/Common/Common.csproj
index cc5869ceeb..55c0f58207 100644
--- a/projects/Test/Common/Common.csproj
+++ b/projects/Test/Common/Common.csproj
@@ -26,6 +26,7 @@
+
diff --git a/projects/Test/Common/IntegrationFixture.cs b/projects/Test/Common/IntegrationFixture.cs
index aba2464e04..91109eaf8d 100644
--- a/projects/Test/Common/IntegrationFixture.cs
+++ b/projects/Test/Common/IntegrationFixture.cs
@@ -89,7 +89,7 @@ public abstract class IntegrationFixture : IAsyncLifetime
static IntegrationFixture()
{
-#if NET6_0_OR_GREATER
+#if NET
S_Random = Random.Shared;
#else
S_Random = new Random();
diff --git a/projects/Test/Common/TestOutputWriterEventListener.cs b/projects/Test/Common/TestOutputWriterEventListener.cs
index d359d1d37c..43d18f57af 100644
--- a/projects/Test/Common/TestOutputWriterEventListener.cs
+++ b/projects/Test/Common/TestOutputWriterEventListener.cs
@@ -76,7 +76,7 @@ protected override void OnEventWritten(EventWrittenEventArgs eventData)
{
try
{
-#if NET6_0_OR_GREATER
+#if NET
if (eventData.Payload.Count > 0)
{
string payloadName = eventData.PayloadNames[0];
diff --git a/projects/Test/Integration/Integration.csproj b/projects/Test/Integration/Integration.csproj
index 585302a85e..31b69369f5 100644
--- a/projects/Test/Integration/Integration.csproj
+++ b/projects/Test/Integration/Integration.csproj
@@ -39,6 +39,7 @@
-->
+
diff --git a/projects/Test/Integration/TestExchangeDeclare.cs b/projects/Test/Integration/TestExchangeDeclare.cs
index cdaa067451..ecff7b2671 100644
--- a/projects/Test/Integration/TestExchangeDeclare.cs
+++ b/projects/Test/Integration/TestExchangeDeclare.cs
@@ -112,6 +112,7 @@ public async Task TestConcurrentExchangeDeclareAndDelete()
var exchangeNames = new ConcurrentBag();
var tasks = new List();
NotSupportedException nse = null;
+ Exception unexpectedException = null;
for (int i = 0; i < 256; i++)
{
var t = Task.Run(async () =>
@@ -129,13 +130,24 @@ public async Task TestConcurrentExchangeDeclareAndDelete()
{
nse = e;
}
+ catch (Exception ex)
+ {
+ unexpectedException = ex;
+ }
});
tasks.Add(t);
}
await Task.WhenAll(tasks);
- Assert.Null(nse);
+ if (nse is not null)
+ {
+ Assert.Fail($"got unexpected NotSupportedException: {nse}");
+ }
+ if (unexpectedException is not null)
+ {
+ Assert.Fail($"got unexpected Exception: {unexpectedException}");
+ }
tasks.Clear();
foreach (string exchangeName in exchangeNames)
@@ -154,13 +166,24 @@ public async Task TestConcurrentExchangeDeclareAndDelete()
{
nse = e;
}
+ catch (Exception ex)
+ {
+ unexpectedException = ex;
+ }
});
tasks.Add(t);
}
await Task.WhenAll(tasks);
- Assert.Null(nse);
+ if (nse is not null)
+ {
+ Assert.Fail($"got unexpected NotSupportedException: {nse}");
+ }
+ if (unexpectedException is not null)
+ {
+ Assert.Fail($"got unexpected Exception: {unexpectedException}");
+ }
}
}
}
diff --git a/projects/Test/OAuth2/OAuth2.csproj b/projects/Test/OAuth2/OAuth2.csproj
index 6710e5d211..d32d77c5dd 100644
--- a/projects/Test/OAuth2/OAuth2.csproj
+++ b/projects/Test/OAuth2/OAuth2.csproj
@@ -28,6 +28,7 @@
+
diff --git a/projects/Test/SequentialIntegration/SequentialIntegration.csproj b/projects/Test/SequentialIntegration/SequentialIntegration.csproj
index dff8ad5fb0..7773206c44 100644
--- a/projects/Test/SequentialIntegration/SequentialIntegration.csproj
+++ b/projects/Test/SequentialIntegration/SequentialIntegration.csproj
@@ -17,6 +17,7 @@
true
true
12.0
+ false
@@ -38,6 +39,7 @@
+
diff --git a/projects/Test/Unit/Unit.csproj b/projects/Test/Unit/Unit.csproj
index fc23c107ac..c11c778a58 100644
--- a/projects/Test/Unit/Unit.csproj
+++ b/projects/Test/Unit/Unit.csproj
@@ -24,6 +24,7 @@
+