question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

I know that Unity support isn’t planned for grpc-dotnet (#710 and #1155). However, since Grpc.Core is going to be deprecated (see The future of gRPC in C# belongs to grpc-dotnet), what is the plan for Unity users? I haven’t seen anything related in the blog post. I know that Unity support was experimental, but are you 100% dropping it?

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:22
  • Comments:49 (14 by maintainers)

github_iconTop GitHub Comments

24reactions
JamesNKcommented, Feb 6, 2023

Grpc.Net.Client on Unity requires Unity to add support for HTTP/2. If HTTP/2 and netstandard2.1 are supported, then Grpc.Net.Client will start working without any changes.

I want this to happen and I asked the Unity team about it here.

Basically, the work required is in Unity. You should tell them that gRPC is important to you so they prioritize it. I don’t know the best way to do that. Comment on Unity Future .NET Development Status?

14reactions
Blackclawscommented, Nov 22, 2021

Alright, its actually even much simpler. You can use all the libraries targeting netstandard2.1 by default, the Grpc.Core.Api needs to be recompiled for netstandard2.1 instead of 2.0 else it won’t link in Unity (the System.Memory issue). You don’t even need to change any files that way.

If you’re using Google.Protobuf (which I guess a lot of you will be) you also need to recompile that for netstandard 2.1 (or include it in the project). You need to be careful there that it actually has a dependency set per target framework in the csproj:

  <ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
    <PackageReference Include="System.Memory" Version="4.5.3" />
    <!-- Needed for netcoreapp3.1 to work correctly. .NET is not able to load the assembly without this -->
    <PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.5.2" />
  </ItemGroup>

where you need to add:

  <ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.1' ">
    <PackageReference Include="System.Memory" Version="4.5.3" />
    <!-- Needed for netcoreapp3.1 to work correctly. .NET is not able to load the assembly without this -->
    <PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
  </ItemGroup>

do note the Version 6.0.0 for System.Runtime.CompilerServices.Unsafe as that is the version that Unity apparently ships with.

So in total you’re going to need the following dlls for Grpc Web to work in Unity:

  • Grpc.Core.Api.dll (recompiled for netstandard 2.1)
  • Grpc.Net.Client.dll (can be copied as a netstandard 2.1 version)
  • Grpc.Net.Client.Web.dll (can be copied as well)
  • Grpc.Net.Common.dll (same)
  • System.Diagnostics.DiagnosticSource.dll (can be copied as is from the nuget package, I’ve used the netstandard 1.3 version)
  • Microsoft.Extensions.Logging.Abstractions.dll (can also be copied from the nuget package, netstandard 2.0 package works fine here)

optionally:

  • Google.Protobuf.dll (recompiled for netstandard 2.1)

You can then use any code generated clients in Unity. I have not tested server mode in any way and I don’t think there is an easy way to get it to work.

For code generated clients you can either add the source or just add any library that you built yourself targeting netstandard2.1.

Maybe in the future Grpc will work without the Web intermediate form, but for now Grpc Web is as good as its going to get and its still faster than REST.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unity Support
Accounts Articles relating to Unity ID accounts, sometimes called UDN, and also Unity Organizations and management.
Read more >
Unity Customer Service: Technical Support & Training
Unity Gaming Services support. Read documentation, watch videos, and access support for Unity Ads, Unity Cloud Build, Unity Analytics, and more.
Read more >
Contact Unity Support
To help us provide effective and timely support, use the Unity Support Contact form to submit your questions and support requests.
Read more >
Success Plans - Technical support
Unity Starter Success. Our entry-level support plan to help you efficiently solve technical issues and get your project back on track. · Unity...
Read more >
Unity Help Desk Contacts
How to contact Unity's customer service via email, live chat support, phone number, social media support, and self-service support.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found