-
Notifications
You must be signed in to change notification settings - Fork 595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trimming and AOT compatibility of this library #1410
Comments
@eerhardt what are the risks of option 1? If we annotation |
The risks are if [EventData]
public class RabbitMqExceptionDetail
{
...
+ public RabbitMqNestedExceptionDetail NestedDetails { get; set; }
}
+public class RabbitMqNestedExceptionDetail
+{
+ public string String1 { get; set; }
+ public string String2 { get; set; }
+} If that ever happened, we wouldn't get a new trim warning (because we suppressed the warning), but So in this scenario, when someone trimmed or AOT'd their app, it would be likely that they wouldn't get event source values written for |
Resolve the trim warning coming from RabbitMqClientEventSource.Error. Preserve the properties of RabbitMqExceptionDetail and suppress the warning. The TimerBasedCredentialRefresherEventSource has warnings as well, but these can be suppressed because the parameters are primitive. In .NET 8 these warnings no longer need to be suppressed because of dotnet/runtime#83751. Fix rabbitmq#1410
Resolve the trim warning coming from RabbitMqClientEventSource.Error. Preserve the properties of RabbitMqExceptionDetail and suppress the warning. The TimerBasedCredentialRefresherEventSource has warnings as well, but these can be suppressed because the parameters are primitive. In .NET 8 these warnings no longer need to be suppressed because of dotnet/runtime#83751. Fix rabbitmq#1410
Right. I think that risk is fairly low. |
Resolve the trim warning coming from RabbitMqClientEventSource.Error. Preserve the properties of RabbitMqExceptionDetail and suppress the warning. The TimerBasedCredentialRefresherEventSource has warnings as well, but these can be suppressed because the parameters are primitive. In .NET 8 these warnings no longer need to be suppressed because of dotnet/runtime#83751. Fix rabbitmq#1410
Resolve the trim warning coming from RabbitMqClientEventSource.Error. Preserve the properties of RabbitMqExceptionDetail and suppress the warning. The TimerBasedCredentialRefresherEventSource has warnings as well, but these can be suppressed because the parameters are primitive. In .NET 8 these warnings no longer need to be suppressed because of dotnet/runtime#83751. Fix rabbitmq#1410
@eerhardt would you mind checking these lines that I had to add to fix a warning? It seems as though your trimming changes will only be compatible in newer .NET environments. Here is the warning:
|
@eerhardt it seems like the warning is to alert users that the analyzers are only supported in later .NET versions, not the trimming itself. Going go go with that! Source - https://blog.martincostello.com/upgrading-to-dotnet-8-part-5-preview-7-and-rc-1-2/ |
The allows the 6.x library to be used in trimmed and native AOT'd applications without any warnings. Since the 6.x branch doesn't target net6.0+, it only targets netstandard2.0 and net462, the #if NET6_0_OR_GREATER checks don't do anything. To resolve this issue, and copy the trimming attributes into this library following the recommendation at https://devblogs.microsoft.com/dotnet/creating-aot-compatible-libraries/#approach-2-define-the-attributes-internally. This allows the library to apply the attributes without targeting net6.0+. Also moving DebugUtil to the test project - porting rabbitmq#1009 from the main branch. Contributes to rabbitmq#1410
@lukebakken - Thank you for merging my change and backporting it to 6.x. I apologize for my delay in response - I've been swamped since being back from a break at the end of the year. The backport to 6.x has some issues. I've opened #1470 to address them. This change will make the 6.x version of the library work in Native AOT'd apps without warnings. I hope it helps. |
@eerhardt I'm really glad you understand this stuff 😅 |
The allows the 6.x library to be used in trimmed and native AOT'd applications without any warnings. Since the 6.x branch doesn't target net6.0+, it only targets netstandard2.0 and net462, the #if NET6_0_OR_GREATER checks don't do anything. To resolve this issue, and copy the trimming attributes into this library following the recommendation at https://devblogs.microsoft.com/dotnet/creating-aot-compatible-libraries/#approach-2-define-the-attributes-internally. This allows the library to apply the attributes without targeting net6.0+. Also moving DebugUtil to the test project - porting rabbitmq#1009 from the main branch. Contributes to rabbitmq#1410 Add AotCompatibility.TestApp Add PS1 to run test app Add AOT test to windows GHA
The allows the 6.x library to be used in trimmed and native AOT'd applications without any warnings. Since the 6.x branch doesn't target net6.0+, it only targets netstandard2.0 and net462, the #if NET6_0_OR_GREATER checks don't do anything. To resolve this issue, and copy the trimming attributes into this library following the recommendation at https://devblogs.microsoft.com/dotnet/creating-aot-compatible-libraries/#approach-2-define-the-attributes-internally. This allows the library to apply the attributes without targeting net6.0+. Also moving DebugUtil to the test project - porting #1009 from the main branch. Contributes to #1410 Add AotCompatibility.TestApp Add PS1 to run test app Add AOT test to windows GHA
Is your feature request related to a problem? Please describe.
I would like to use RabbitMQ.Client in an app that has been published for native AOT. See https://learn.microsoft.com/dotnet/core/deploying/native-aot/?tabs=net8. However, when I do I'm getting a single warning coming from RabbitMQ's Error Logging EventSource code:
ILC : Trim analysis warning IL2026: RabbitMQ.Client.Logging.RabbitMqClientEventSource.Error(String,RabbitMqExceptionDetail): Using member 'System.Diagnostics.Tracing.EventSource.WriteEvent(Int32,Object[])' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. EventSource will serialize the whole object graph. Trimmer will not safely handle this case because properties may be trimmed.
This warning is coming from
rabbitmq-dotnet-client/projects/RabbitMQ.Client/client/logging/RabbitMqClientEventSource.cs
Lines 73 to 77 in a0321c6
and
rabbitmq-dotnet-client/projects/RabbitMQ.Client/client/logging/RabbitMqExceptionDetail.cs
Lines 38 to 66 in a0321c6
This EventSource code is writing a complex object
RabbitMqExceptionDetail
to an Event. When EventSource sees a complex object, it uses Reflection to get all the properties recursively and gets the values to write to the Event. This is not trimming compatible because the Properties might be trimmed. If they are, the Event data will be different between a trimmed and non-trimmed app.The AOT/trimming tools produce warnings like the above to let developers know which parts of their code will break when the app is published. You can read more about preparing a library for trimming at https://learn.microsoft.com/dotnet/core/deploying/trimming/prepare-libraries-for-trimming.
Describe the solution you'd like
We should fix the above warning so developers can use RabbitMQ.Client in AOT and trimming apps without warnings, and their apps continue to work
Describe alternatives you've considered
I can think of 2 different approaches to fixing this trimming warning:
RabbitMqExceptionDetail
are preserved in a trimmed app and suppress the warning. Something like the following:This would ensure the properties are preserved and the warning no longer occurs.
object[]
of primitive values. This same behavior can be simulated by using the WriteEventCore method, which is trim compatible by design. However it takes more code, and we would need to be careful to ensure we don't change the format of the data being emitted from this EventSource event, so we didn't break existing listeners.My recommendation would be to take approach (1) above.
Additional context
No response
The text was updated successfully, but these errors were encountered: