diff --git a/build.bat b/build.bat
index 9425b5fce7..f3d4a251de 100644
--- a/build.bat
+++ b/build.bat
@@ -1,5 +1,5 @@
@ECHO OFF
set DOTNET_CLI_TELEMETRY_OPTOUT=1
-dotnet restore --verbosity=normal .\RabbitMQDotNetClient.sln
-dotnet run --verbosity=normal --framework net6.0 --project .\projects\Apigen\Apigen.csproj --apiName:AMQP_0_9_1 .\projects\specs\amqp0-9-1.stripped.xml .\gensrc\autogenerated-api-0-9-1.cs
-dotnet build --verbosity=normal .\RabbitMQDotNetClient.sln
+dotnet restore .\RabbitMQDotNetClient.sln
+dotnet run --framework net6.0 --project .\projects\Apigen\Apigen.csproj --apiName:AMQP_0_9_1 .\projects\specs\amqp0-9-1.stripped.xml .\gensrc\autogenerated-api-0-9-1.cs
+dotnet build .\RabbitMQDotNetClient.sln
diff --git a/projects/RabbitMQ.Client/RabbitMQ.Client.csproj b/projects/RabbitMQ.Client/RabbitMQ.Client.csproj
index eb4266865a..7851d56912 100755
--- a/projects/RabbitMQ.Client/RabbitMQ.Client.csproj
+++ b/projects/RabbitMQ.Client/RabbitMQ.Client.csproj
@@ -5,6 +5,8 @@
true
$(NoWarn);CS1591
true
+ true
+ true
RabbitMQ Client Library for .NET
VMware
VMware, Inc. or its affiliates.
diff --git a/projects/RabbitMQ.Client/client/api/ICredentialsRefresher.cs b/projects/RabbitMQ.Client/client/api/ICredentialsRefresher.cs
index a609aff052..c3fa966519 100644
--- a/projects/RabbitMQ.Client/client/api/ICredentialsRefresher.cs
+++ b/projects/RabbitMQ.Client/client/api/ICredentialsRefresher.cs
@@ -36,7 +36,7 @@
namespace RabbitMQ.Client
{
- public delegate void NotifyCredentialRefreshed(bool succesfully);
+ public delegate void NotifyCredentialRefreshed(bool successfully);
public interface ICredentialsRefresher
{
@@ -54,10 +54,16 @@ public class TimerBasedCredentialRefresherEventSource : EventSource
[Event(2)]
public void Unregistered(string name) => WriteEvent(2, "UnRegistered", name);
[Event(3)]
+#if NET6_0_OR_GREATER
+ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "Parameters to this method are primitive and are trimmer safe")]
+#endif
public void ScheduledTimer(string name, double interval) => WriteEvent(3, "ScheduledTimer", name, interval);
[Event(4)]
public void TriggeredTimer(string name) => WriteEvent(4, "TriggeredTimer", name);
[Event(5)]
+#if NET6_0_OR_GREATER
+ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "Parameters to this method are primitive and are trimmer safe")]
+#endif
public void RefreshedCredentials(string name, bool succesfully) => WriteEvent(5, "RefreshedCredentials", name, succesfully);
[Event(6)]
public void AlreadyRegistered(string name) => WriteEvent(6, "AlreadyRegistered", name);
diff --git a/projects/RabbitMQ.Client/client/logging/RabbitMqClientEventSource.cs b/projects/RabbitMQ.Client/client/logging/RabbitMqClientEventSource.cs
index 8cc5f759e9..4481abcca1 100644
--- a/projects/RabbitMQ.Client/client/logging/RabbitMqClientEventSource.cs
+++ b/projects/RabbitMQ.Client/client/logging/RabbitMqClientEventSource.cs
@@ -34,64 +34,57 @@
namespace RabbitMQ.Client.Logging
{
- [EventSource(Name="rabbitmq-dotnet-client")]
+ [EventSource(Name = "rabbitmq-dotnet-client")]
public sealed class RabbitMqClientEventSource : EventSource
{
public class Keywords
{
public const EventKeywords Log = (EventKeywords)1;
}
-#if NET452
- public RabbitMqClientEventSource() : base()
- {
- }
-#else
public RabbitMqClientEventSource() : base(EventSourceSettings.EtwSelfDescribingEventFormat)
{
}
-#endif
- public static RabbitMqClientEventSource Log = new RabbitMqClientEventSource ();
+ public static RabbitMqClientEventSource Log = new RabbitMqClientEventSource();
[Event(1, Message = "INFO", Keywords = Keywords.Log, Level = EventLevel.Informational)]
public void Info(string message)
{
- if(IsEnabled())
+ if (IsEnabled())
WriteEvent(1, message);
}
[Event(2, Message = "WARN", Keywords = Keywords.Log, Level = EventLevel.Warning)]
public void Warn(string message)
{
- if(IsEnabled())
+ if (IsEnabled())
WriteEvent(2, message);
}
-#if NET452
+
[Event(3, Message = "ERROR", Keywords = Keywords.Log, Level = EventLevel.Error)]
- public void Error(string message, string detail)
+ public void Error(string message, RabbitMqExceptionDetail ex)
{
- if(IsEnabled())
- this.WriteEvent(3, message, detail);
- }
+ if (IsEnabled())
+ {
+#if NET6_0_OR_GREATER
+ WriteExceptionEvent(message, ex);
+
+ [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "The properties are preserved with the DynamicallyAccessedMembers attribute.")]
+ void WriteExceptionEvent<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T>(string message, T ex)
+ {
+ WriteEvent(3, message, ex);
+ }
#else
- [Event(3, Message = "ERROR", Keywords = Keywords.Log, Level = EventLevel.Error)]
- public void Error(string message, RabbitMqExceptionDetail ex)
- {
- if(IsEnabled())
WriteEvent(3, message, ex);
- }
#endif
+ }
+ }
[NonEvent]
public void Error(string message, Exception ex)
{
-
-#if NET452
- Error(message, ex.ToString());
-#else
Error(message, new RabbitMqExceptionDetail(ex));
-#endif
}
}
}
diff --git a/projects/RabbitMQ.Client/client/logging/RabbitMqExceptionDetail.cs b/projects/RabbitMQ.Client/client/logging/RabbitMqExceptionDetail.cs
index 279089bfd5..90f8e4c508 100644
--- a/projects/RabbitMQ.Client/client/logging/RabbitMqExceptionDetail.cs
+++ b/projects/RabbitMQ.Client/client/logging/RabbitMqExceptionDetail.cs
@@ -46,7 +46,7 @@ public RabbitMqExceptionDetail(Exception ex)
Type = ex.GetType().FullName;
Message = ex.Message;
StackTrace = ex.StackTrace;
- if(ex.InnerException != null)
+ if (ex.InnerException != null)
{
InnerException = ex.InnerException.ToString();
}
@@ -63,6 +63,11 @@ public RabbitMqExceptionDetail(IDictionary ex)
}
}
+
+ // NOTE: This type is used to write EventData in RabbitMqClientEventSource.Error. To make it trim-compatible, these properties are preserved
+ // in RabbitMqClientEventSource. If RabbitMqExceptionDetail gets a property that is a complex type, we need to ensure the nested properties are
+ // preserved as well.
+
public string Type { get; private set; }
public string Message { get; private set; }
public string StackTrace { get; private set; }
diff --git a/projects/Unit/APIApproval.Approve.verified.txt b/projects/Unit/APIApproval.Approve.verified.txt
index c67881833a..061b0a6d19 100644
--- a/projects/Unit/APIApproval.Approve.verified.txt
+++ b/projects/Unit/APIApproval.Approve.verified.txt
@@ -571,7 +571,7 @@ namespace RabbitMQ.Client
System.Threading.Tasks.Task ConnectAsync(string host, int port);
System.Net.Sockets.NetworkStream GetStream();
}
- public delegate void NotifyCredentialRefreshed(bool succesfully);
+ public delegate void NotifyCredentialRefreshed(bool successfully);
public class PlainMechanism : RabbitMQ.Client.IAuthMechanism
{
public PlainMechanism() { }