Skip to content

Commit

Permalink
Add blazor hint (when possible) (#248)
Browse files Browse the repository at this point in the history
* re #247, add [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]

(rev the build SDK so we can use NET5_0_OR_GREATER build symbol)

* add release notes tweak
  • Loading branch information
mgravell authored Jul 18, 2022
1 parent dc26897 commit e4487ee
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ image: Visual Studio 2019

install:
- cmd: >-
choco install dotnet-sdk --version 6.0.201
choco install dotnet-sdk --version 6.0.302
skip_branch_with_pr: true
skip_tags: true
Expand Down
4 changes: 4 additions & 0 deletions docs/releasenotes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release Notes

## unreleased

- try to improve blazor linker support (i.e. avoid removal of necessary APIs)

## 1.0.136

- add .NET 5 target
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "3.0.100",
"version": "6.0.302",
"rollForward": "latestMajor",
"allowPrerelease": false
}
Expand Down
8 changes: 8 additions & 0 deletions src/protobuf-net.Grpc/Client/GrpcClientFactory.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Grpc.Core;
using ProtoBuf.Grpc.Configuration;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;

namespace ProtoBuf.Grpc.Client
Expand All @@ -10,6 +11,13 @@ namespace ProtoBuf.Grpc.Client
/// </summary>
public static class GrpcClientFactory
{
#if NET5_0_OR_GREATER
// it is *intended* that this attribute usage will help the linker not remove things that we need
// see: https://docs.microsoft.com/en-us/dotnet/core/deploying/trimming/prepare-libraries-for-trimming#dynamicallyaccessedmembers
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
#endif
internal static readonly Type ClientBaseType = typeof(ClientBase);

private const string SwitchAllowUnencryptedHttp2 = "System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport";
/// <summary>
/// Allows HttpClient to use HTTP/2 without TLS
Expand Down
3 changes: 2 additions & 1 deletion src/protobuf-net.Grpc/Internal/ProxyEmitter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Grpc.Core;
using ProtoBuf.Grpc.Client;
using ProtoBuf.Grpc.Configuration;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -135,7 +136,7 @@ internal static Func<CallInvoker, TService> CreateViaActivator<TService>(Type ty
[MethodImpl(MethodImplOptions.NoInlining)]
internal static Func<CallInvoker, TService> EmitFactory<TService>(BinderConfiguration binderConfig)
{
Type baseType = typeof(ClientBase);
Type baseType = GrpcClientFactory.ClientBaseType;

var callInvoker = baseType.GetProperty("CallInvoker", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)?.GetGetMethod(true);
if (callInvoker == null || callInvoker.ReturnType != typeof(CallInvoker) || callInvoker.GetParameters().Length != 0)
Expand Down

0 comments on commit e4487ee

Please sign in to comment.