From e0d1b074b15d5e8f3ea62585f50e1c1e86f07e4c Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Fri, 5 Nov 2021 20:16:35 +1300 Subject: [PATCH 1/3] Fix server trim error from dependency injection --- .../IGrpcServiceActivator.cs | 8 +++++++- .../Model/IServiceMethodProvider.cs | 9 ++++++++- .../Grpc.AspNetCore.FunctionalTests.csproj | 1 + ...spNetCore.Server.ClientFactory.Tests.csproj | 1 + .../Grpc.AspNetCore.Server.Tests.csproj | 1 + .../Grpc.Net.ClientFactory.Tests.csproj | 1 + .../LinkerTestsClient/LinkerTestsClient.csproj | 18 ++++-------------- .../LinkerTestsWebsite.csproj | 16 +++------------- 8 files changed, 26 insertions(+), 29 deletions(-) diff --git a/src/Grpc.AspNetCore.Server/IGrpcServiceActivator.cs b/src/Grpc.AspNetCore.Server/IGrpcServiceActivator.cs index 0147ce9c6..326725a2f 100644 --- a/src/Grpc.AspNetCore.Server/IGrpcServiceActivator.cs +++ b/src/Grpc.AspNetCore.Server/IGrpcServiceActivator.cs @@ -17,7 +17,9 @@ #endregion using System; +using System.Diagnostics.CodeAnalysis; using System.Threading.Tasks; +using Grpc.AspNetCore.Server.Internal; namespace Grpc.AspNetCore.Server { @@ -25,7 +27,11 @@ namespace Grpc.AspNetCore.Server /// A activator abstraction. /// /// The service type. - public interface IGrpcServiceActivator where TGrpcService : class + public interface IGrpcServiceActivator< +#if NET5_0_OR_GREATER + [DynamicallyAccessedMembers(DefaultGrpcServiceActivator.ServiceAccessibility)] +#endif + TGrpcService> where TGrpcService : class { /// /// Creates a service. diff --git a/src/Grpc.AspNetCore.Server/Model/IServiceMethodProvider.cs b/src/Grpc.AspNetCore.Server/Model/IServiceMethodProvider.cs index be5f37bb8..e345cce79 100644 --- a/src/Grpc.AspNetCore.Server/Model/IServiceMethodProvider.cs +++ b/src/Grpc.AspNetCore.Server/Model/IServiceMethodProvider.cs @@ -16,6 +16,9 @@ #endregion +using System.Diagnostics.CodeAnalysis; +using Grpc.AspNetCore.Server.Model.Internal; + namespace Grpc.AspNetCore.Server.Model { /// @@ -28,7 +31,11 @@ namespace Grpc.AspNetCore.Server.Model /// instances are invoked in the order they are registered. /// /// - public interface IServiceMethodProvider where TService : class + public interface IServiceMethodProvider< +#if NET5_0_OR_GREATER + [DynamicallyAccessedMembers(ProviderServiceBinder.ServiceAccessibility)] +#endif + TService> where TService : class { /// /// Called to execute the provider. diff --git a/test/FunctionalTests/Grpc.AspNetCore.FunctionalTests.csproj b/test/FunctionalTests/Grpc.AspNetCore.FunctionalTests.csproj index 6c190ed18..e9e6dbdbd 100644 --- a/test/FunctionalTests/Grpc.AspNetCore.FunctionalTests.csproj +++ b/test/FunctionalTests/Grpc.AspNetCore.FunctionalTests.csproj @@ -3,6 +3,7 @@ netcoreapp3.1;net5.0;net6.0 false + true True diff --git a/test/Grpc.AspNetCore.Server.ClientFactory.Tests/Grpc.AspNetCore.Server.ClientFactory.Tests.csproj b/test/Grpc.AspNetCore.Server.ClientFactory.Tests/Grpc.AspNetCore.Server.ClientFactory.Tests.csproj index cfc3ee81b..aaa549a22 100644 --- a/test/Grpc.AspNetCore.Server.ClientFactory.Tests/Grpc.AspNetCore.Server.ClientFactory.Tests.csproj +++ b/test/Grpc.AspNetCore.Server.ClientFactory.Tests/Grpc.AspNetCore.Server.ClientFactory.Tests.csproj @@ -3,6 +3,7 @@ netcoreapp3.1;net5.0;net6.0 false + true diff --git a/test/Grpc.AspNetCore.Server.Tests/Grpc.AspNetCore.Server.Tests.csproj b/test/Grpc.AspNetCore.Server.Tests/Grpc.AspNetCore.Server.Tests.csproj index 3532472a3..06fd71f4a 100644 --- a/test/Grpc.AspNetCore.Server.Tests/Grpc.AspNetCore.Server.Tests.csproj +++ b/test/Grpc.AspNetCore.Server.Tests/Grpc.AspNetCore.Server.Tests.csproj @@ -3,6 +3,7 @@ netcoreapp3.1;net5.0;net6.0 false + true diff --git a/test/Grpc.Net.ClientFactory.Tests/Grpc.Net.ClientFactory.Tests.csproj b/test/Grpc.Net.ClientFactory.Tests/Grpc.Net.ClientFactory.Tests.csproj index a690b4d95..47a2b7406 100644 --- a/test/Grpc.Net.ClientFactory.Tests/Grpc.Net.ClientFactory.Tests.csproj +++ b/test/Grpc.Net.ClientFactory.Tests/Grpc.Net.ClientFactory.Tests.csproj @@ -3,6 +3,7 @@ netcoreapp3.1;net5.0;net472;net6.0 false + true true diff --git a/testassets/LinkerTestsClient/LinkerTestsClient.csproj b/testassets/LinkerTestsClient/LinkerTestsClient.csproj index 983a04fcb..4b65e16ea 100644 --- a/testassets/LinkerTestsClient/LinkerTestsClient.csproj +++ b/testassets/LinkerTestsClient/LinkerTestsClient.csproj @@ -1,29 +1,19 @@  - net5.0 + net6.0 Exe - true - Link + + - - - - - link - - - - - - + \ No newline at end of file diff --git a/testassets/LinkerTestsWebsite/LinkerTestsWebsite.csproj b/testassets/LinkerTestsWebsite/LinkerTestsWebsite.csproj index b625cfe59..c350ad804 100644 --- a/testassets/LinkerTestsWebsite/LinkerTestsWebsite.csproj +++ b/testassets/LinkerTestsWebsite/LinkerTestsWebsite.csproj @@ -1,11 +1,9 @@  - net5.0 + net6.0 Exe - true - Link @@ -13,18 +11,10 @@ + + - - - - - link - - - - - From 06c923ec47cdc179902df6d4355b31aef3b23268 Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Sat, 6 Nov 2021 15:54:01 +1300 Subject: [PATCH 2/3] Fix more warnings --- .../GrpcEndpointRouteBuilderExtensions.cs | 6 +----- src/Grpc.AspNetCore.Server/IGrpcServiceActivator.cs | 2 +- .../CallHandlers/ClientStreamingServerCallHandler.cs | 7 ++++++- .../CallHandlers/DuplexStreamingServerCallHandler.cs | 7 ++++++- .../Internal/CallHandlers/ServerCallHandlerBase.cs | 8 ++++++-- .../CallHandlers/ServerStreamingServerCallHandler.cs | 11 ++++++----- .../Internal/CallHandlers/UnaryServerCallHandler.cs | 10 ++++++---- .../Internal/DefaultGrpcServiceActivator.cs | 5 +---- .../Internal/GrpcProtocolConstants.cs | 5 +++++ .../Internal/ServerCallHandlerFactory.cs | 7 ++++++- .../Model/IServiceMethodProvider.cs | 4 ++-- .../Model/Internal/BinderServiceModelProvider.cs | 3 ++- .../Model/Internal/ProviderServiceBinder.cs | 8 ++------ .../Model/Internal/ServiceRouteBuilder.cs | 7 ++++++- .../Model/ServiceMethodProviderContext.cs | 7 ++++++- .../Server/ClientStreamingServerMethodInvoker.cs | 8 +++++++- .../Server/DuplexStreamingServerMethodInvoker.cs | 8 +++++++- src/Shared/Server/ServerMethodInvokerBase.cs | 8 +++++++- .../Server/ServerStreamingServerMethodInvoker.cs | 8 +++++++- src/Shared/Server/UnaryServerMethodInvoker.cs | 8 +++++++- test/FunctionalTests/Linker/LinkerTests.cs | 2 +- testassets/LinkerTestsClient/LinkerTestsClient.csproj | 5 +++++ .../LinkerTestsWebsite/LinkerTestsWebsite.csproj | 5 +++++ 23 files changed, 108 insertions(+), 41 deletions(-) diff --git a/src/Grpc.AspNetCore.Server/GrpcEndpointRouteBuilderExtensions.cs b/src/Grpc.AspNetCore.Server/GrpcEndpointRouteBuilderExtensions.cs index 6647b213b..fb7c74ab0 100644 --- a/src/Grpc.AspNetCore.Server/GrpcEndpointRouteBuilderExtensions.cs +++ b/src/Grpc.AspNetCore.Server/GrpcEndpointRouteBuilderExtensions.cs @@ -30,10 +30,6 @@ namespace Microsoft.AspNetCore.Builder /// public static class GrpcEndpointRouteBuilderExtensions { -#if NET5_0_OR_GREATER - private const DynamicallyAccessedMemberTypes ServiceAccessibility = DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods; -#endif - /// /// Maps incoming requests to the specified type. /// @@ -42,7 +38,7 @@ public static class GrpcEndpointRouteBuilderExtensions /// A for endpoints associated with the service. public static GrpcServiceEndpointConventionBuilder MapGrpcService< #if NET5_0_OR_GREATER - [DynamicallyAccessedMembers(ServiceAccessibility)] + [DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)] #endif TService>(this IEndpointRouteBuilder builder) where TService : class { diff --git a/src/Grpc.AspNetCore.Server/IGrpcServiceActivator.cs b/src/Grpc.AspNetCore.Server/IGrpcServiceActivator.cs index 326725a2f..61e14a674 100644 --- a/src/Grpc.AspNetCore.Server/IGrpcServiceActivator.cs +++ b/src/Grpc.AspNetCore.Server/IGrpcServiceActivator.cs @@ -29,7 +29,7 @@ namespace Grpc.AspNetCore.Server /// The service type. public interface IGrpcServiceActivator< #if NET5_0_OR_GREATER - [DynamicallyAccessedMembers(DefaultGrpcServiceActivator.ServiceAccessibility)] + [DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)] #endif TGrpcService> where TGrpcService : class { diff --git a/src/Grpc.AspNetCore.Server/Internal/CallHandlers/ClientStreamingServerCallHandler.cs b/src/Grpc.AspNetCore.Server/Internal/CallHandlers/ClientStreamingServerCallHandler.cs index 71b390c97..3f0434875 100644 --- a/src/Grpc.AspNetCore.Server/Internal/CallHandlers/ClientStreamingServerCallHandler.cs +++ b/src/Grpc.AspNetCore.Server/Internal/CallHandlers/ClientStreamingServerCallHandler.cs @@ -16,6 +16,7 @@ #endregion +using System.Diagnostics.CodeAnalysis; using System.Threading.Tasks; using Grpc.Core; using Grpc.Shared.Server; @@ -24,7 +25,11 @@ namespace Grpc.AspNetCore.Server.Internal.CallHandlers { - internal class ClientStreamingServerCallHandler : ServerCallHandlerBase + internal class ClientStreamingServerCallHandler< +#if NET5_0_OR_GREATER + [DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)] +#endif + TService, TRequest, TResponse> : ServerCallHandlerBase where TRequest : class where TResponse : class where TService : class diff --git a/src/Grpc.AspNetCore.Server/Internal/CallHandlers/DuplexStreamingServerCallHandler.cs b/src/Grpc.AspNetCore.Server/Internal/CallHandlers/DuplexStreamingServerCallHandler.cs index 6ad8296d4..f1ecb4248 100644 --- a/src/Grpc.AspNetCore.Server/Internal/CallHandlers/DuplexStreamingServerCallHandler.cs +++ b/src/Grpc.AspNetCore.Server/Internal/CallHandlers/DuplexStreamingServerCallHandler.cs @@ -17,6 +17,7 @@ #endregion using System; +using System.Diagnostics.CodeAnalysis; using System.Threading.Tasks; using Grpc.AspNetCore.Server.Model; using Grpc.Core; @@ -27,7 +28,11 @@ namespace Grpc.AspNetCore.Server.Internal.CallHandlers { - internal class DuplexStreamingServerCallHandler : ServerCallHandlerBase + internal class DuplexStreamingServerCallHandler< +#if NET5_0_OR_GREATER + [DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)] +#endif + TService, TRequest, TResponse> : ServerCallHandlerBase where TRequest : class where TResponse : class where TService : class diff --git a/src/Grpc.AspNetCore.Server/Internal/CallHandlers/ServerCallHandlerBase.cs b/src/Grpc.AspNetCore.Server/Internal/CallHandlers/ServerCallHandlerBase.cs index 4d131f79f..6ad8fbd98 100644 --- a/src/Grpc.AspNetCore.Server/Internal/CallHandlers/ServerCallHandlerBase.cs +++ b/src/Grpc.AspNetCore.Server/Internal/CallHandlers/ServerCallHandlerBase.cs @@ -17,8 +17,8 @@ #endregion using System; +using System.Diagnostics.CodeAnalysis; using System.Threading.Tasks; -using Grpc.AspNetCore.Server.Model; using Grpc.Core; using Grpc.Shared.Server; using Microsoft.AspNetCore.Http; @@ -29,7 +29,11 @@ namespace Grpc.AspNetCore.Server.Internal.CallHandlers { - internal abstract class ServerCallHandlerBase + internal abstract class ServerCallHandlerBase< +#if NET5_0_OR_GREATER + [DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)] +#endif + TService, TRequest, TResponse> where TService : class where TRequest : class where TResponse : class diff --git a/src/Grpc.AspNetCore.Server/Internal/CallHandlers/ServerStreamingServerCallHandler.cs b/src/Grpc.AspNetCore.Server/Internal/CallHandlers/ServerStreamingServerCallHandler.cs index 19346ca0c..be0e1d438 100644 --- a/src/Grpc.AspNetCore.Server/Internal/CallHandlers/ServerStreamingServerCallHandler.cs +++ b/src/Grpc.AspNetCore.Server/Internal/CallHandlers/ServerStreamingServerCallHandler.cs @@ -16,18 +16,19 @@ #endregion -using System; +using System.Diagnostics.CodeAnalysis; using System.Threading.Tasks; -using Grpc.AspNetCore.Server.Model; -using Grpc.Core; using Grpc.Shared.Server; using Microsoft.AspNetCore.Http; -using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; namespace Grpc.AspNetCore.Server.Internal.CallHandlers { - internal class ServerStreamingServerCallHandler : ServerCallHandlerBase + internal class ServerStreamingServerCallHandler< +#if NET5_0_OR_GREATER + [DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)] +#endif + TService, TRequest, TResponse> : ServerCallHandlerBase where TRequest : class where TResponse : class where TService : class diff --git a/src/Grpc.AspNetCore.Server/Internal/CallHandlers/UnaryServerCallHandler.cs b/src/Grpc.AspNetCore.Server/Internal/CallHandlers/UnaryServerCallHandler.cs index e03cfd518..a05f5ce84 100644 --- a/src/Grpc.AspNetCore.Server/Internal/CallHandlers/UnaryServerCallHandler.cs +++ b/src/Grpc.AspNetCore.Server/Internal/CallHandlers/UnaryServerCallHandler.cs @@ -16,18 +16,20 @@ #endregion -using System; +using System.Diagnostics.CodeAnalysis; using System.Threading.Tasks; -using Grpc.AspNetCore.Server.Model; using Grpc.Core; using Grpc.Shared.Server; using Microsoft.AspNetCore.Http; -using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; namespace Grpc.AspNetCore.Server.Internal.CallHandlers { - internal class UnaryServerCallHandler : ServerCallHandlerBase + internal class UnaryServerCallHandler< +#if NET5_0_OR_GREATER + [DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)] +#endif + TService, TRequest, TResponse> : ServerCallHandlerBase where TRequest : class where TResponse : class where TService : class diff --git a/src/Grpc.AspNetCore.Server/Internal/DefaultGrpcServiceActivator.cs b/src/Grpc.AspNetCore.Server/Internal/DefaultGrpcServiceActivator.cs index 7fc897fcf..2acdbd081 100644 --- a/src/Grpc.AspNetCore.Server/Internal/DefaultGrpcServiceActivator.cs +++ b/src/Grpc.AspNetCore.Server/Internal/DefaultGrpcServiceActivator.cs @@ -25,13 +25,10 @@ namespace Grpc.AspNetCore.Server.Internal { internal sealed class DefaultGrpcServiceActivator< #if NET5_0_OR_GREATER - [DynamicallyAccessedMembers(ServiceAccessibility)] + [DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)] #endif TGrpcService> : IGrpcServiceActivator where TGrpcService : class { -#if NET5_0_OR_GREATER - internal const DynamicallyAccessedMemberTypes ServiceAccessibility = DynamicallyAccessedMemberTypes.PublicConstructors; -#endif private static readonly Lazy _objectFactory = new Lazy(static () => ActivatorUtilities.CreateFactory(typeof(TGrpcService), Type.EmptyTypes)); public GrpcActivatorHandle Create(IServiceProvider serviceProvider) diff --git a/src/Grpc.AspNetCore.Server/Internal/GrpcProtocolConstants.cs b/src/Grpc.AspNetCore.Server/Internal/GrpcProtocolConstants.cs index a53a31c28..4830235cc 100644 --- a/src/Grpc.AspNetCore.Server/Internal/GrpcProtocolConstants.cs +++ b/src/Grpc.AspNetCore.Server/Internal/GrpcProtocolConstants.cs @@ -18,6 +18,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using Microsoft.AspNetCore.Http; using Microsoft.Net.Http.Headers; @@ -127,5 +128,9 @@ internal static int GetCancelErrorCode(string protocol) return Http2ResetStreamCancel; #endif } + +#if NET5_0_OR_GREATER + internal const DynamicallyAccessedMemberTypes ServiceAccessibility = DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods; +#endif } } diff --git a/src/Grpc.AspNetCore.Server/Internal/ServerCallHandlerFactory.cs b/src/Grpc.AspNetCore.Server/Internal/ServerCallHandlerFactory.cs index 5f46895dd..07d48ae10 100644 --- a/src/Grpc.AspNetCore.Server/Internal/ServerCallHandlerFactory.cs +++ b/src/Grpc.AspNetCore.Server/Internal/ServerCallHandlerFactory.cs @@ -17,6 +17,7 @@ #endregion using System; +using System.Diagnostics.CodeAnalysis; using System.Threading.Tasks; using Grpc.AspNetCore.Server.Internal.CallHandlers; using Grpc.AspNetCore.Server.Model; @@ -32,7 +33,11 @@ namespace Grpc.AspNetCore.Server.Internal /// /// Creates server call handlers. Provides a place to get services that call handlers will use. /// - internal partial class ServerCallHandlerFactory where TService : class + internal partial class ServerCallHandlerFactory< +#if NET5_0_OR_GREATER + [DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)] +#endif + TService> where TService : class { private readonly ILoggerFactory _loggerFactory; private readonly IGrpcServiceActivator _serviceActivator; diff --git a/src/Grpc.AspNetCore.Server/Model/IServiceMethodProvider.cs b/src/Grpc.AspNetCore.Server/Model/IServiceMethodProvider.cs index e345cce79..9bd35157b 100644 --- a/src/Grpc.AspNetCore.Server/Model/IServiceMethodProvider.cs +++ b/src/Grpc.AspNetCore.Server/Model/IServiceMethodProvider.cs @@ -17,7 +17,7 @@ #endregion using System.Diagnostics.CodeAnalysis; -using Grpc.AspNetCore.Server.Model.Internal; +using Grpc.AspNetCore.Server.Internal; namespace Grpc.AspNetCore.Server.Model { @@ -33,7 +33,7 @@ namespace Grpc.AspNetCore.Server.Model /// public interface IServiceMethodProvider< #if NET5_0_OR_GREATER - [DynamicallyAccessedMembers(ProviderServiceBinder.ServiceAccessibility)] + [DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)] #endif TService> where TService : class { diff --git a/src/Grpc.AspNetCore.Server/Model/Internal/BinderServiceModelProvider.cs b/src/Grpc.AspNetCore.Server/Model/Internal/BinderServiceModelProvider.cs index 634bbff67..5be9627c5 100644 --- a/src/Grpc.AspNetCore.Server/Model/Internal/BinderServiceModelProvider.cs +++ b/src/Grpc.AspNetCore.Server/Model/Internal/BinderServiceModelProvider.cs @@ -18,6 +18,7 @@ using System; using System.Diagnostics.CodeAnalysis; +using Grpc.AspNetCore.Server.Internal; using Grpc.Shared.Server; using Microsoft.Extensions.Logging; using Log = Grpc.AspNetCore.Server.Model.Internal.BinderServiceMethodProviderLog; @@ -26,7 +27,7 @@ namespace Grpc.AspNetCore.Server.Model.Internal { internal class BinderServiceMethodProvider< #if NET5_0_OR_GREATER - [DynamicallyAccessedMembers(ProviderServiceBinder.ServiceAccessibility)] + [DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)] #endif TService> : IServiceMethodProvider where TService : class { diff --git a/src/Grpc.AspNetCore.Server/Model/Internal/ProviderServiceBinder.cs b/src/Grpc.AspNetCore.Server/Model/Internal/ProviderServiceBinder.cs index e601507ad..8c54a4a39 100644 --- a/src/Grpc.AspNetCore.Server/Model/Internal/ProviderServiceBinder.cs +++ b/src/Grpc.AspNetCore.Server/Model/Internal/ProviderServiceBinder.cs @@ -20,6 +20,7 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Reflection; +using Grpc.AspNetCore.Server.Internal; using Grpc.Core; using Microsoft.AspNetCore.Routing; @@ -27,15 +28,10 @@ namespace Grpc.AspNetCore.Server.Model.Internal { internal class ProviderServiceBinder< #if NET5_0_OR_GREATER - [DynamicallyAccessedMembers(ServiceAccessibility)] + [DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)] #endif TService> : ServiceBinderBase where TService : class { -#if NET5_0_OR_GREATER - // Non-public methods is required by GetMethod overload that has a BindingFlags argument. - internal const DynamicallyAccessedMemberTypes ServiceAccessibility = DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods; -#endif - private readonly ServiceMethodProviderContext _context; private readonly Type _declaringType; diff --git a/src/Grpc.AspNetCore.Server/Model/Internal/ServiceRouteBuilder.cs b/src/Grpc.AspNetCore.Server/Model/Internal/ServiceRouteBuilder.cs index 2db7f63d1..2fc499f95 100644 --- a/src/Grpc.AspNetCore.Server/Model/Internal/ServiceRouteBuilder.cs +++ b/src/Grpc.AspNetCore.Server/Model/Internal/ServiceRouteBuilder.cs @@ -18,6 +18,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Linq; using Grpc.AspNetCore.Server.Internal; using Grpc.Core; @@ -31,7 +32,11 @@ namespace Grpc.AspNetCore.Server.Model.Internal { - internal class ServiceRouteBuilder where TService : class + internal class ServiceRouteBuilder< +#if NET5_0_OR_GREATER + [DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)] +#endif + TService> where TService : class { private readonly IEnumerable> _serviceMethodProviders; private readonly ServerCallHandlerFactory _serverCallHandlerFactory; diff --git a/src/Grpc.AspNetCore.Server/Model/ServiceMethodProviderContext.cs b/src/Grpc.AspNetCore.Server/Model/ServiceMethodProviderContext.cs index f326802d0..e7349c4da 100644 --- a/src/Grpc.AspNetCore.Server/Model/ServiceMethodProviderContext.cs +++ b/src/Grpc.AspNetCore.Server/Model/ServiceMethodProviderContext.cs @@ -17,6 +17,7 @@ #endregion using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using Grpc.AspNetCore.Server.Internal; using Grpc.AspNetCore.Server.Model.Internal; using Grpc.Core; @@ -29,7 +30,11 @@ namespace Grpc.AspNetCore.Server.Model /// A context for . /// /// Service type for the context. - public class ServiceMethodProviderContext where TService : class + public class ServiceMethodProviderContext< +#if NET5_0_OR_GREATER + [DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)] +#endif + TService> where TService : class { private readonly ServerCallHandlerFactory _serverCallHandlerFactory; diff --git a/src/Shared/Server/ClientStreamingServerMethodInvoker.cs b/src/Shared/Server/ClientStreamingServerMethodInvoker.cs index 11ea58ef3..582db3535 100644 --- a/src/Shared/Server/ClientStreamingServerMethodInvoker.cs +++ b/src/Shared/Server/ClientStreamingServerMethodInvoker.cs @@ -16,8 +16,10 @@ #endregion +using System.Diagnostics.CodeAnalysis; using System.Threading.Tasks; using Grpc.AspNetCore.Server; +using Grpc.AspNetCore.Server.Internal; using Grpc.AspNetCore.Server.Model; using Grpc.Core; using Microsoft.AspNetCore.Http; @@ -30,7 +32,11 @@ namespace Grpc.Shared.Server /// Service type for this method. /// Request message type for this method. /// Response message type for this method. - internal sealed class ClientStreamingServerMethodInvoker : ServerMethodInvokerBase + internal sealed class ClientStreamingServerMethodInvoker< +#if NET5_0_OR_GREATER + [DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)] +#endif + TService, TRequest, TResponse> : ServerMethodInvokerBase where TRequest : class where TResponse : class where TService : class diff --git a/src/Shared/Server/DuplexStreamingServerMethodInvoker.cs b/src/Shared/Server/DuplexStreamingServerMethodInvoker.cs index 4c2e7e7b0..08018b14e 100644 --- a/src/Shared/Server/DuplexStreamingServerMethodInvoker.cs +++ b/src/Shared/Server/DuplexStreamingServerMethodInvoker.cs @@ -16,8 +16,10 @@ #endregion +using System.Diagnostics.CodeAnalysis; using System.Threading.Tasks; using Grpc.AspNetCore.Server; +using Grpc.AspNetCore.Server.Internal; using Grpc.AspNetCore.Server.Model; using Grpc.Core; using Microsoft.AspNetCore.Http; @@ -30,7 +32,11 @@ namespace Grpc.Shared.Server /// Service type for this method. /// Request message type for this method. /// Response message type for this method. - internal sealed class DuplexStreamingServerMethodInvoker : ServerMethodInvokerBase + internal sealed class DuplexStreamingServerMethodInvoker< +#if NET5_0_OR_GREATER + [DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)] +#endif + TService, TRequest, TResponse> : ServerMethodInvokerBase where TRequest : class where TResponse : class where TService : class diff --git a/src/Shared/Server/ServerMethodInvokerBase.cs b/src/Shared/Server/ServerMethodInvokerBase.cs index 2e9e72c23..62811c331 100644 --- a/src/Shared/Server/ServerMethodInvokerBase.cs +++ b/src/Shared/Server/ServerMethodInvokerBase.cs @@ -16,7 +16,9 @@ #endregion +using System.Diagnostics.CodeAnalysis; using Grpc.AspNetCore.Server; +using Grpc.AspNetCore.Server.Internal; using Grpc.Core; namespace Grpc.Shared.Server @@ -27,7 +29,11 @@ namespace Grpc.Shared.Server /// Service type for this method. /// Request message type for this method. /// Response message type for this method. - internal abstract class ServerMethodInvokerBase + internal abstract class ServerMethodInvokerBase< +#if NET5_0_OR_GREATER + [DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)] +#endif + TService, TRequest, TResponse> where TRequest : class where TResponse : class where TService : class diff --git a/src/Shared/Server/ServerStreamingServerMethodInvoker.cs b/src/Shared/Server/ServerStreamingServerMethodInvoker.cs index ada5a4117..4d2517f28 100644 --- a/src/Shared/Server/ServerStreamingServerMethodInvoker.cs +++ b/src/Shared/Server/ServerStreamingServerMethodInvoker.cs @@ -16,8 +16,10 @@ #endregion +using System.Diagnostics.CodeAnalysis; using System.Threading.Tasks; using Grpc.AspNetCore.Server; +using Grpc.AspNetCore.Server.Internal; using Grpc.AspNetCore.Server.Model; using Grpc.Core; using Microsoft.AspNetCore.Http; @@ -30,7 +32,11 @@ namespace Grpc.Shared.Server /// Service type for this method. /// Request message type for this method. /// Response message type for this method. - internal sealed class ServerStreamingServerMethodInvoker : ServerMethodInvokerBase + internal sealed class ServerStreamingServerMethodInvoker< +#if NET5_0_OR_GREATER + [DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)] +#endif + TService, TRequest, TResponse> : ServerMethodInvokerBase where TRequest : class where TResponse : class where TService : class diff --git a/src/Shared/Server/UnaryServerMethodInvoker.cs b/src/Shared/Server/UnaryServerMethodInvoker.cs index f39009f90..98c1eca65 100644 --- a/src/Shared/Server/UnaryServerMethodInvoker.cs +++ b/src/Shared/Server/UnaryServerMethodInvoker.cs @@ -17,9 +17,11 @@ #endregion using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.ExceptionServices; using System.Threading.Tasks; using Grpc.AspNetCore.Server; +using Grpc.AspNetCore.Server.Internal; using Grpc.AspNetCore.Server.Model; using Grpc.Core; using Microsoft.AspNetCore.Http; @@ -32,7 +34,11 @@ namespace Grpc.Shared.Server /// Service type for this method. /// Request message type for this method. /// Response message type for this method. - internal sealed class UnaryServerMethodInvoker : ServerMethodInvokerBase + internal sealed class UnaryServerMethodInvoker< +#if NET5_0_OR_GREATER + [DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)] +#endif + TService, TRequest, TResponse> : ServerMethodInvokerBase where TRequest : class where TResponse : class where TService : class diff --git a/test/FunctionalTests/Linker/LinkerTests.cs b/test/FunctionalTests/Linker/LinkerTests.cs index b5c4fe535..1772a97ab 100644 --- a/test/FunctionalTests/Linker/LinkerTests.cs +++ b/test/FunctionalTests/Linker/LinkerTests.cs @@ -103,7 +103,7 @@ private static async Task PublishAppAsync(string path, string outputPath) var process = new DotNetProcess(); try { - process.Start($"publish {resolvedPath} -r {GetRuntimeIdentifier()} -c Release -o {outputPath}"); + process.Start($"publish {resolvedPath} -r {GetRuntimeIdentifier()} -c Release -o {outputPath} --self-contained"); await process.WaitForExitAsync().TimeoutAfter(Timeout); } catch (Exception ex) diff --git a/testassets/LinkerTestsClient/LinkerTestsClient.csproj b/testassets/LinkerTestsClient/LinkerTestsClient.csproj index 4b65e16ea..459556d47 100644 --- a/testassets/LinkerTestsClient/LinkerTestsClient.csproj +++ b/testassets/LinkerTestsClient/LinkerTestsClient.csproj @@ -4,6 +4,11 @@ net6.0 Exe true + + + + $(WarningsNotAsErrors);IL2104;IL2026 + $(NoWarn);IL2104;IL2026 diff --git a/testassets/LinkerTestsWebsite/LinkerTestsWebsite.csproj b/testassets/LinkerTestsWebsite/LinkerTestsWebsite.csproj index c350ad804..c8a7f8e90 100644 --- a/testassets/LinkerTestsWebsite/LinkerTestsWebsite.csproj +++ b/testassets/LinkerTestsWebsite/LinkerTestsWebsite.csproj @@ -4,6 +4,11 @@ net6.0 Exe true + + + + $(WarningsNotAsErrors);IL2104;IL2026 + $(NoWarn);IL2104;IL2026 From 2b91b56c6cd5838100086821cebf4bf3cc3772fd Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Mon, 8 Nov 2021 17:38:02 +1300 Subject: [PATCH 3/3] PR feedback --- testassets/LinkerTestsClient/LinkerTestsClient.csproj | 4 +++- testassets/LinkerTestsWebsite/LinkerTestsWebsite.csproj | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/testassets/LinkerTestsClient/LinkerTestsClient.csproj b/testassets/LinkerTestsClient/LinkerTestsClient.csproj index 459556d47..483e4c97a 100644 --- a/testassets/LinkerTestsClient/LinkerTestsClient.csproj +++ b/testassets/LinkerTestsClient/LinkerTestsClient.csproj @@ -5,7 +5,7 @@ Exe true - + $(WarningsNotAsErrors);IL2104;IL2026 $(NoWarn);IL2104;IL2026 @@ -14,7 +14,9 @@ + + diff --git a/testassets/LinkerTestsWebsite/LinkerTestsWebsite.csproj b/testassets/LinkerTestsWebsite/LinkerTestsWebsite.csproj index c8a7f8e90..841abca6a 100644 --- a/testassets/LinkerTestsWebsite/LinkerTestsWebsite.csproj +++ b/testassets/LinkerTestsWebsite/LinkerTestsWebsite.csproj @@ -5,7 +5,7 @@ Exe true - + $(WarningsNotAsErrors);IL2104;IL2026 $(NoWarn);IL2104;IL2026