Open NoahStolk opened 6 months ago
Needs review with the team.
@NoahStolk Thanks for the issue report. We have a larger effort in our internal backlog to make this library NativeAOT compatible. This is one the the things we would consider. Related discussion https://github.com/awslabs/aws-dotnet-messaging/discussions/109.
Describe the feature
The
MessageBusBuilder
class exposes various methods that acceptType
instances or type parameters that are used to dynamically construct instances of said types. For example, in theMessageBusBuilder.AddMessageHandler
method, theTHandler
type is used to dynamically construct an instance of that type.This can and should be indicated by adding DynamicallyAccessedMembersAttribute to the type parameter. This allows tools such as ReSharper to detect that this type is created dynamically. Adding this attribute would also prevent code from being trimmed/removed incorrectly when compiling to native code using Native AOT.
Use Case
Currently, ReSharper complains that my handler type is never constructed and should be removed because it is seen as "dead code". I also believe (but have not yet tested this) that my handler type would be removed if I enabled trimming or compiled my application to native code using Native AOT, which would cause runtime exceptions. There are various workarounds for this, but the obvious fix would be to just include the attribute here.
Proposed Solution
Add the attribute where necessary. Example usages of the attribute can be found in the ASP.NET Core runtime. For example,
AddSingleton
,AddScoped
, andAddTransient
use this attribute:Other Information
No response
Acknowledgements
AWS.Messaging (or related) package versions
AWS.Messaging 0.9.1
Targeted .NET Platform
.NET 8
Operating System and version
Windows 11