Skip to content

Support Native AOT#1857

Open
0x5bfa wants to merge 2 commits into
robinrodricks:masterfrom
0x5bfa:aot
Open

Support Native AOT#1857
0x5bfa wants to merge 2 commits into
robinrodricks:masterfrom
0x5bfa:aot

Conversation

@0x5bfa

@0x5bfa 0x5bfa commented Jun 25, 2026

Copy link
Copy Markdown

Resolves #1856

These were the new AOT-related issues, just FYI:

D:\source\FluentFTP\FluentFTP\Helpers\ValuePrinter.cs(15,21): warning IL2075: 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties' in call to 'System.Type.GetProperties(BindingFlags)'. The return value of method 'System.Object.GetType()' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to. [D:\source\FluentFTP\FluentFTP\FluentFTP.csproj::TargetFramework=net9.0]
D:\source\FluentFTP\FluentFTP\Client\BaseClient\Logger.cs(29,54): warning IL2026: Using member 'System.Reflection.MethodBase.GetCurrentMethod()' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Metadata for the method might be incomplete or removed. [D:\source\FluentFTP\FluentFTP\FluentFTP.csproj::TargetFramework=net9.0]
D:\source\FluentFTP\FluentFTP\Streams\FtpSocketStream.cs(1530,21): warning IL2072: 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor' in call to 'System.Activator.CreateInstance(Type)'. The return value of method 'FluentFTP.FtpConfig.CustomStream.get' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to. [D:\source\FluentFTP\FluentFTP\FluentFTP.csproj::TargetFramework=net9.0]
D:\source\FluentFTP\FluentFTP\Streams\FtpSslStream.cs(298,11): warning IL2070: 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicFields', 'DynamicallyAccessedMemberTypes.NonPublicFields' in call to 'System.Type.GetFields(BindingFlags)'. The parameter 't' of method 'FluentFTP.Streams.ReflectUtil.GetAllFields(Type)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to. [D:\source\FluentFTP\FluentFTP\FluentFTP.csproj::TargetFramework=net9.0]
D:\source\FluentFTP\FluentFTP\Streams\FtpSslStream.cs(305,11): warning IL2070: 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties', 'DynamicallyAccessedMemberTypes.NonPublicProperties' in call to 'System.Type.GetProperties(BindingFlags)'. The parameter 't' of method 'FluentFTP.Streams.ReflectUtil.GetAllProperties(Type)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to. [D:\source\FluentFTP\FluentFTP\FluentFTP.csproj::TargetFramework=net9.0]

Copilot AI review requested due to automatic review settings June 25, 2026 05:34
@0x5bfa

0x5bfa commented Jun 25, 2026

Copy link
Copy Markdown
Author

There may be non statically analyzable issues, but it should be good enough to annotate he project as AOT-safe.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates FluentFTP to be compatible with Native AOT / trimming scenarios (per #1856) by removing or constraining reflection-heavy code paths and adding the necessary trimming annotations and package metadata.

Changes:

  • Mark the NuGet package as AOT compatible and add trimming annotations for CustomStream to satisfy Activator.CreateInstance(Type) requirements.
  • Remove reflection-based argument printing to avoid trim/AOT warnings, and add a targeted ToString() override to keep AutoDetect logging useful.
  • Restrict the FtpSslStream reflection-based close-notify hack to net462 / netstandard2.0, while using SslStream.ShutdownAsync on newer TFMs.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
FluentFTP/Streams/FtpSslStream.cs Gates reflection-based SSL close-notify implementation to older TFMs for AOT/trimming compatibility.
FluentFTP/Model/Functions/FtpAutoDetectConfig.cs Adds ToString() to improve log output without reflection.
FluentFTP/Model/FtpConfig.cs Adds DynamicallyAccessedMembers annotation to support trimming-safe custom stream instantiation.
FluentFTP/Helpers/ValuePrinter.cs Removes reflection-based object property printing to avoid AOT-related warnings.
FluentFTP/FluentFTP.csproj Declares the package as AOT compatible.
FluentFTP/Client/BaseClient/Logger.cs Removes MethodBase.GetCurrentMethod() usage to avoid trimming warnings.
Comments suppressed due to low confidence (1)

FluentFTP/Streams/FtpSslStream.cs:103

  • The XML doc comment for SslDirectCall says "Valid only on .NET Framework", but this code is now also compiled for NETSTANDARD2_0 (and contains a NETSTANDARD branch). Please update the comment to avoid misleading consumers/maintainers.
	/// <summary>
	/// Reflection hack to issue an SSL Close Notify Alert to cleanly shutdown an SSL session
	/// Valid only on .NET Framework
	/// </summary>

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread FluentFTP/Model/Functions/FtpAutoDetectConfig.cs
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@0x5bfa

0x5bfa commented Jun 26, 2026

Copy link
Copy Markdown
Author

FYI @robinrodricks @FanDjango

// Do not use "None" - it can connect to TLS13, but Session Resume won't work, so a successful AutoDetect will be a false truth.
};

public override string ToString() {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why??

return "null";
}

var type = obj.GetType();

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use #if AOT sections to keep older code for older platforms. dont delete.

@robinrodricks

Copy link
Copy Markdown
Owner

Awaiting changes to be made before I can merge @0x5bfa

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Native AOT

3 participants