Skip to content

Conversation

@snakefoot
Copy link
Contributor

@snakefoot snakefoot commented Jul 19, 2025

Propagate to help AOT-build-users, instead of hiding with UnconditionalSuppressMessage.

@snakefoot snakefoot added this to the 6.0.2 milestone Jul 19, 2025
@coderabbitai
Copy link

coderabbitai bot commented Jul 19, 2025

Walkthrough

The changes introduce the RequiresUnreferencedCodeAttribute to signal methods incompatible with code trimming, particularly those using reflection or dynamic assembly loading. Methods in AssemblyExtensionLoader and its interface are annotated accordingly, and obsolete methods are removed. In LoggingConfigurationParser, suppression attributes are applied to methods that trigger trimming warnings, and obsolete usages are refactored.

Changes

File(s) Change Summary
src/NLog/Config/AssemblyExtensionLoader.cs, IAssemblyExtensionLoader Removed obsolete LoadTypeFromName. Added [RequiresUnreferencedCode] to methods involving assembly/type loading. Updated interface signatures.
src/NLog/Config/LoggingConfigurationParser.cs Added suppression attributes to private methods triggering trimming warnings. Refactored extension registration logic to avoid obsolete methods. Added private wrapper for extension scanning.
src/NLog/Internal/DynamicallyAccessedMemberTypes.cs Added internal RequiresUnreferencedCodeAttribute class to support annotation of methods requiring unreferenced code.

Poem

In the warren of code where assemblies hop,
New attributes warn where the trimmers might stop.
Obsolete paths are swept from the field,
Suppressions and signals—our intentions revealed.
With careful reflection, the loader now knows,
Where rabbits and runtime must not overexpose.
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7098d50 and 66a8b8f.

📒 Files selected for processing (3)
  • src/NLog/Config/AssemblyExtensionLoader.cs (8 hunks)
  • src/NLog/Config/LoggingConfigurationParser.cs (4 hunks)
  • src/NLog/Internal/DynamicallyAccessedMemberTypes.cs (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
src/NLog/Internal/DynamicallyAccessedMemberTypes.cs (3)
src/NLog/Internal/AssemblyMetadataAttribute.cs (1)
  • AttributeUsage (38-44)
src/NLog/Internal/Guard.cs (1)
  • AttributeUsage (38-47)
src/NLog/Internal/OverloadResolutionPriorityAttribute.cs (1)
  • AttributeUsage (41-57)
src/NLog/Config/AssemblyExtensionLoader.cs (1)
src/NLog/Config/ConfigurationItemFactory.cs (3)
  • ConfigurationItemFactory (55-564)
  • ConfigurationItemFactory (94-97)
  • ConfigurationItemFactory (99-120)
🔇 Additional comments (13)
src/NLog/Internal/DynamicallyAccessedMemberTypes.cs (1)

232-265: Well-designed attribute implementation for AOT compatibility.

The RequiresUnreferencedCodeAttribute is properly implemented with appropriate AttributeUsage targeting methods, constructors, and classes. The attribute correctly includes a required message parameter and an optional URL property for additional guidance, following standard .NET attribute patterns.

src/NLog/Config/LoggingConfigurationParser.cs (5)

201-201: Appropriate call delegation to suppression-annotated method.

The direct call to ConfigurationItemFactory.Default.AssemblyLoader.ScanForAutoLoadExtensions(ConfigurationItemFactory.Default) has been properly replaced with a call to the new ScanForAutoLoadExtensions() method, which handles trimming warning suppression.


207-211: Proper encapsulation of trimming-incompatible code.

The new ScanForAutoLoadExtensions() method correctly wraps the assembly scanning call with UnconditionalSuppressMessage attribute for IL2026, providing clear justification for suppressing the trimming warning.


363-383: Correctly handles obsolete method replacement with proper warning suppression.

The RegisterExtension method has been properly updated to replace the obsolete LoadTypeFromName call with a two-step process using PropertyTypeConverter.ConvertToType and ConfigurationItemFactory.Default.RegisterType. The pragma directives appropriately suppress the obsolete warning for the necessary call.


385-385: Appropriate suppression attribute for assembly loading.

The UnconditionalSuppressMessage attribute for IL2026 is correctly applied to ParseExtensionWithAssemblyFile method, which performs assembly loading operations incompatible with trimming.


410-410: Consistent suppression pattern for assembly operations.

The UnconditionalSuppressMessage attribute for IL2026 is appropriately applied to ParseExtensionWithAssemblyName method, maintaining consistency with other assembly loading operations in the file.

src/NLog/Config/AssemblyExtensionLoader.cs (7)

46-47: Proper annotation for assembly loading method.

The RequiresUnreferencedCodeAttribute with message "Assembly.GetTypes() Incompatible with trimming." is correctly applied to LoadAssemblyFromName method, which performs type scanning operations incompatible with AOT scenarios.


60-61: Appropriate trimming warning for type scanning.

The RequiresUnreferencedCodeAttribute is properly applied to LoadAssembly method, which calls SafeGetTypes and performs reflection-based type registration that's incompatible with trimming.


101-102: Correct annotation for reflection-based type loading.

The SafeGetTypes method appropriately uses RequiresUnreferencedCodeAttribute as it directly calls Assembly.GetTypes(), which is indeed incompatible with trimming scenarios.


256-257: Consistent annotation pattern for assembly operations.

Both LoadAssemblyFromPath methods are correctly annotated with RequiresUnreferencedCodeAttribute using appropriate messages that distinguish between Assembly.GetTypes() and Assembly.LoadFrom() incompatibilities.

Also applies to: 264-265


312-313: Proper attribution for extension scanning methods.

The LoadNLogExtensionAssemblies and RegisterAppDomainAssemblies methods are appropriately marked with trimming incompatibility warnings, as they perform dynamic assembly loading and type scanning operations.

Also applies to: 349-350


466-467: Accurate annotation for dynamic assembly loading.

The LoadAssemblyFromPath method correctly uses RequiresUnreferencedCodeAttribute with "Assembly.LoadFrom() Incompatible with trimming." message, which accurately describes the trimming incompatibility.


524-534: Interface properly annotated for contract compliance.

The IAssemblyExtensionLoader interface methods are correctly annotated with RequiresUnreferencedCodeAttribute to maintain contract consistency with the implementing class, ensuring callers are aware of trimming incompatibilities.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
50.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@snakefoot snakefoot merged commit 53b21e4 into NLog:dev Jul 19, 2025
5 of 6 checks passed
This was referenced Jul 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant