Skip to content

Conversation

@AArnott
Copy link
Member

@AArnott AArnott commented Jun 6, 2025

This doesn't get StreamJsonRpc to be NativeAOT safe in any significant way, but now attributes guard the areas that are not safe, and gives us a backlog of things to improve on.

AArnott and others added 4 commits June 12, 2025 22:42
Since ProxyGeneration always generates IL code using RefEmit, it will never work in native AOT'd apps. But currently it is still brought into the app because RpcMarshalableConverterFactory (used by SystemTextJsonFormatter by default) eventually calls into it.

To remove references to Newtonsoft.Json, we can cut this off in AOT'd apps by checking if dynamic code isn't supported and throw an exception. This will allow ProxyGeneration to be trimmed from the final app.

This isn't a perfect fix, but instead a compromise. The best fix would be to make RpcMarshalableConverterFactory work correctly in AOT'd apps.
Cut ProxyGeneration out if dynamic code isn't supported
davidfowl pushed a commit to dotnet/aspire that referenced this pull request Jun 17, 2025
* Start the beginning of AOT'ing the Aspire.Cli.

Depends on microsoft/vs-streamjsonrpc#1196

* Revert cli.csproj changes

* Revert Designer.cs changes

* Share state object types across CLI and Hosting.

* Split the Backchannel data types across assemblies again

* Revert launchSettings.json
eerhardt and others added 5 commits June 17, 2025 19:18
…bility.

There are a couple patterns here:

- Use GetMemberWithSameMetadataDefinitionAs to reflect on generic types/methods in a statically verifiable fashion. This method only exists in .NET 6+.
- Suppress warnings when using GetInterfaces when the Type is annotated as preserve 'All'. dotnet/linker#1731
- When looking for a hard-coded interface like IProgress<T>, any preserved Type that implements the interface won't have the interface trimmed.
- MethodNameMap uses GetInterfaceMap, which may not work in all cases. See dotnet/runtime#89157
- Use for loop to avoid Roslyn analyzer warning.
- Condition the suppression on !NET10.
…bility. (#1207)

* Refactor code and annotations to fix all warnings in NativeAOTCompatibility.

There are a couple patterns here:

- Use GetMemberWithSameMetadataDefinitionAs to reflect on generic types/methods in a statically verifiable fashion. This method only exists in .NET 6+.
- Suppress warnings when using GetInterfaces when the Type is annotated as preserve 'All'. dotnet/linker#1731
- When looking for a hard-coded interface like IProgress<T>, any preserved Type that implements the interface won't have the interface trimmed.
- MethodNameMap uses GetInterfaceMap, which may not work in all cases. See dotnet/runtime#89157

* Refactor TrackerHelper to not need DynamicallyAccessedMembers attribute on the Type parameter.

* Respond to PR feedback

- Use for loop to avoid Roslyn analyzer warning.
- Condition the suppression on !NET10.
@AArnott AArnott marked this pull request as ready for review June 19, 2025 00:29
- Remove leftover comment
- Fix some incorrect trimming annotations
Copy link
Member

@eerhardt eerhardt left a comment

Choose a reason for hiding this comment

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

These changes LGTM.

I found a few minor pieces of feedback which I addressed in #1210.

@AArnott AArnott enabled auto-merge June 19, 2025 16:41
@AArnott AArnott merged commit 06368ad into main Jun 19, 2025
6 checks passed
@AArnott AArnott deleted the NativeAOT branch June 19, 2025 16:55
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.

4 participants