Skip to content

Commit dbf2115

Browse files
authored
Fix new linker warnings (#1372)
* 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. * Bump Nerdbank.MessagePack to 0.12.39-rc
2 parents 174cf3d + 3bffe49 commit dbf2115

File tree

5 files changed

+34
-19
lines changed

5 files changed

+34
-19
lines changed

Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<PackageVersion Include="Microsoft.VisualStudio.Threading.Only" Version="$(VisualStudioThreadingVersion)" />
2828
<PackageVersion Include="Microsoft.VisualStudio.Threading" Version="$(VisualStudioThreadingVersion)" />
2929
<PackageVersion Include="Microsoft.VisualStudio.Validation" Version="17.13.22" />
30-
<PackageVersion Include="Nerdbank.MessagePack" Version="0.12.28-rc" />
30+
<PackageVersion Include="Nerdbank.MessagePack" Version="0.12.39-rc" />
3131
<PackageVersion Include="Nerdbank.Streams" Version="2.13.16" />
3232
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
3333
<PackageVersion Include="System.Collections.Immutable" Version="8.0.0" />

src/StreamJsonRpc/LoadableTypeCollection.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
using System.Collections;
55
using System.Collections.Immutable;
66
using System.Diagnostics.CodeAnalysis;
7-
using System.Runtime.CompilerServices;
8-
using Microsoft;
97

108
namespace StreamJsonRpc;
119

@@ -62,14 +60,19 @@ internal bool TryGetType(string fullName, [NotNullWhen(true), DynamicallyAccesse
6260
return false;
6361
}
6462

65-
private struct LoadableType([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] Type type) : IEquatable<LoadableType>
63+
private struct LoadableType : IEquatable<LoadableType>
6664
{
65+
public LoadableType([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] Type type)
66+
{
67+
this.Type = type;
68+
}
69+
6770
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
68-
public Type Type => type;
71+
public Type Type { get; }
6972

7073
public bool Equals(LoadableType other) => this.Type == other.Type;
7174

72-
public override int GetHashCode() => type.GetHashCode();
75+
public override int GetHashCode() => this.Type.GetHashCode();
7376

7477
public override bool Equals(object? obj) => obj is LoadableType other && this.Equals(other);
7578
}

src/StreamJsonRpc/Reflection/JsonRpcProxyMappingAttribute.cs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,27 @@ namespace StreamJsonRpc.Reflection;
1010
/// An attribute that is used by our source generator to map an RPC interface to a
1111
/// source generated proxy class.
1212
/// </summary>
13-
/// <param name="proxyClass">
14-
/// The source generated proxy class.
15-
/// This must implement the interface the attribute is applied to,
16-
/// derive from <see cref="ProxyBase"/>,
17-
/// and declare a public constructor with a particular signature.
18-
/// </param>
1913
[AttributeUsage(AttributeTargets.Interface, AllowMultiple = true)]
2014
[EditorBrowsable(EditorBrowsableState.Never)]
21-
public class JsonRpcProxyMappingAttribute(
22-
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.Interfaces)] Type proxyClass) : Attribute
15+
public class JsonRpcProxyMappingAttribute : Attribute
2316
{
2417
/// <summary>
25-
/// Gets the proxy class type implements the RPC interface.
18+
/// Initializes a new instance of the <see cref="JsonRpcProxyMappingAttribute"/> class.
19+
/// </summary>
20+
/// <param name="proxyClass">
21+
/// The source generated proxy class.
22+
/// This must implement the interface the attribute is applied to,
23+
/// derive from <see cref="ProxyBase"/>,
24+
/// and declare a public constructor with a particular signature.
25+
/// </param>
26+
public JsonRpcProxyMappingAttribute([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.Interfaces)] Type proxyClass)
27+
{
28+
this.ProxyClass = proxyClass;
29+
}
30+
31+
/// <summary>
32+
/// Gets the proxy class type that implements the RPC interface.
2633
/// </summary>
2734
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.Interfaces)]
28-
public Type ProxyClass => proxyClass;
35+
public Type ProxyClass { get; }
2936
}

src/StreamJsonRpc/RpcTargetMetadata.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,10 +491,15 @@ private static IReadOnlyList<Type> GetMissingInterfacesFromSet([DynamicallyAcces
491491

492492
private static MethodInfo GetMethodInfo(IMethodShape shape) => (MethodInfo)(shape.MethodBase ?? throw new ArgumentException(Resources.FormatAttributeProviderRequired($"{shape.DeclaringType.Type.FullName}.{shape.Name}"), nameof(shape)));
493493

494-
internal struct RpcTargetInterface([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods | DynamicallyAccessedMemberTypes.PublicEvents)] Type iface)
494+
internal struct RpcTargetInterface
495495
{
496+
public RpcTargetInterface([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods | DynamicallyAccessedMemberTypes.PublicEvents)] Type iface)
497+
{
498+
this.Interface = iface;
499+
}
500+
496501
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods | DynamicallyAccessedMemberTypes.PublicEvents)]
497-
public Type Interface => iface;
502+
public Type Interface { get; }
498503
}
499504

500505
/// <summary>

test/NativeAOTCompatibility.Test/NativeAOTCompatibility.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Import Project="..\AOT.props" />
33

44
<PropertyGroup>
5-
<TargetFramework>net8.0</TargetFramework>
5+
<TargetFramework>net10.0</TargetFramework>
66
<TrimmerSingleWarn>false</TrimmerSingleWarn>
77
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
88
<EnableStreamJsonRpcInterceptors>true</EnableStreamJsonRpcInterceptors>

0 commit comments

Comments
 (0)