From 869df46f9a59f8ca3cdb653a057fed35a76b08c8 Mon Sep 17 00:00:00 2001 From: Andrew Arnott Date: Thu, 4 Dec 2025 08:22:21 -0700 Subject: [PATCH 1/2] Fix new linker warnings This requires us to stop using C# primary constructors where linker attributes need to be applied to parameters because C# doesn't copy those attributes to the fields. --- src/StreamJsonRpc/LoadableTypeCollection.cs | 13 +++++---- .../JsonRpcProxyMappingAttribute.cs | 27 ++++++++++++------- src/StreamJsonRpc/RpcTargetMetadata.cs | 9 +++++-- .../NativeAOTCompatibility.Test.csproj | 2 +- 4 files changed, 33 insertions(+), 18 deletions(-) diff --git a/src/StreamJsonRpc/LoadableTypeCollection.cs b/src/StreamJsonRpc/LoadableTypeCollection.cs index d1ca2489f..fcf580482 100644 --- a/src/StreamJsonRpc/LoadableTypeCollection.cs +++ b/src/StreamJsonRpc/LoadableTypeCollection.cs @@ -4,8 +4,6 @@ using System.Collections; using System.Collections.Immutable; using System.Diagnostics.CodeAnalysis; -using System.Runtime.CompilerServices; -using Microsoft; namespace StreamJsonRpc; @@ -62,14 +60,19 @@ internal bool TryGetType(string fullName, [NotNullWhen(true), DynamicallyAccesse return false; } - private struct LoadableType([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] Type type) : IEquatable + private struct LoadableType : IEquatable { + public LoadableType([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] Type type) + { + this.Type = type; + } + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] - public Type Type => type; + public Type Type { get; } public bool Equals(LoadableType other) => this.Type == other.Type; - public override int GetHashCode() => type.GetHashCode(); + public override int GetHashCode() => this.Type.GetHashCode(); public override bool Equals(object? obj) => obj is LoadableType other && this.Equals(other); } diff --git a/src/StreamJsonRpc/Reflection/JsonRpcProxyMappingAttribute.cs b/src/StreamJsonRpc/Reflection/JsonRpcProxyMappingAttribute.cs index 2df17d303..cc26592b9 100644 --- a/src/StreamJsonRpc/Reflection/JsonRpcProxyMappingAttribute.cs +++ b/src/StreamJsonRpc/Reflection/JsonRpcProxyMappingAttribute.cs @@ -10,20 +10,27 @@ namespace StreamJsonRpc.Reflection; /// An attribute that is used by our source generator to map an RPC interface to a /// source generated proxy class. /// -/// -/// The source generated proxy class. -/// This must implement the interface the attribute is applied to, -/// derive from , -/// and declare a public constructor with a particular signature. -/// [AttributeUsage(AttributeTargets.Interface, AllowMultiple = true)] [EditorBrowsable(EditorBrowsableState.Never)] -public class JsonRpcProxyMappingAttribute( - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.Interfaces)] Type proxyClass) : Attribute +public class JsonRpcProxyMappingAttribute : Attribute { /// - /// Gets the proxy class type implements the RPC interface. + /// Initializes a new instance of the class. + /// + /// + /// The source generated proxy class. + /// This must implement the interface the attribute is applied to, + /// derive from , + /// and declare a public constructor with a particular signature. + /// + public JsonRpcProxyMappingAttribute([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.Interfaces)] Type proxyClass) + { + this.ProxyClass = proxyClass; + } + + /// + /// Gets the proxy class type that implements the RPC interface. /// [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.Interfaces)] - public Type ProxyClass => proxyClass; + public Type ProxyClass { get; } } diff --git a/src/StreamJsonRpc/RpcTargetMetadata.cs b/src/StreamJsonRpc/RpcTargetMetadata.cs index 5cd8285f8..30abb6c83 100644 --- a/src/StreamJsonRpc/RpcTargetMetadata.cs +++ b/src/StreamJsonRpc/RpcTargetMetadata.cs @@ -491,10 +491,15 @@ private static IReadOnlyList GetMissingInterfacesFromSet([DynamicallyAcces private static MethodInfo GetMethodInfo(IMethodShape shape) => (MethodInfo)(shape.MethodBase ?? throw new ArgumentException(Resources.FormatAttributeProviderRequired($"{shape.DeclaringType.Type.FullName}.{shape.Name}"), nameof(shape))); - internal struct RpcTargetInterface([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods | DynamicallyAccessedMemberTypes.PublicEvents)] Type iface) + internal struct RpcTargetInterface { + public RpcTargetInterface([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods | DynamicallyAccessedMemberTypes.PublicEvents)] Type iface) + { + this.Interface = iface; + } + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods | DynamicallyAccessedMemberTypes.PublicEvents)] - public Type Interface => iface; + public Type Interface { get; } } /// diff --git a/test/NativeAOTCompatibility.Test/NativeAOTCompatibility.Test.csproj b/test/NativeAOTCompatibility.Test/NativeAOTCompatibility.Test.csproj index 9352f7809..0f60cc881 100644 --- a/test/NativeAOTCompatibility.Test/NativeAOTCompatibility.Test.csproj +++ b/test/NativeAOTCompatibility.Test/NativeAOTCompatibility.Test.csproj @@ -2,7 +2,7 @@ - net8.0 + net10.0 false true true From 3bffe49f4044758fb0de4e5321d7bbf7457ff50f Mon Sep 17 00:00:00 2001 From: Andrew Arnott Date: Thu, 4 Dec 2025 08:31:55 -0700 Subject: [PATCH 2/2] Bump Nerdbank.MessagePack to 0.12.39-rc --- Directory.Packages.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 2dd489a7f..5df56d494 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -27,7 +27,7 @@ - +