grpc: Unity Package: System.Memory.dll version mismatch

What version of gRPC and what language are you using?

grpc_unity_package.2.27.0-dev C#

What operating system (Linux, Windows,…) and version?

Windows 10 2004

What runtime / compiler are you using (e.g. python version or version of gcc)

Unity 2019.3.0f6

What did you do?

I downloaded the last unity package (2.27.0) from https://packages.grpc.io/, extracted it to the Asset/Plugins folder.

What did you expect to see?

The plugin to work.

What did you see instead?

The Google.Protobuf dll failed to load with the following messages:

Error: Could not load signature of Google.Protobuf.ByteString:get_Span due to: Could not load file or assembly 'System.Memory, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. assembly:System.Memory, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 type:<unknown type> member:(null) signature:<none>
Unloading broken assembly Assets/Plugins/Google.Protobuf/lib/net45/Google.Protobuf.dll, this assembly can cause crashes in the runtime

It appears that Google.Protobuf.dll has an assembly reference to version 4.0.1.0 (4.5.2)of System.Memory, but Grpc.Core has a reference to version 4.0.1.1 (4.5.3), and that’s the version that is included in the unity package, so the version used by Protobuf is missing.

Anything else we should know about your project / environment?

I tried upgrading the reference in the Google.Protobuf project to 4.0.1.1 in Visual Studio, but it gave the following error:

Severity	Code	Description	Project	File	Line	Suppression State
Error	NU1202	Package System.Memory 4.5.3 is not compatible with netstandard1.0 (.NETStandard,Version=v1.0). Package System.Memory 4.5.3 supports:
  - netcoreapp2.1 (.NETCoreApp,Version=v2.1)
  - netstandard1.1 (.NETStandard,Version=v1.1)
  - netstandard2.0 (.NETStandard,Version=v2.0)	Google.Protobuf	<removed>\code\protobuf\csharp\src\Google.Protobuf\Google.Protobuf.csproj	1	

Downgrading the version used by Grpc seemed to work locally, but that seems less than desirable. Unity doesn’t seem to support loading multiple versions of the same dll or bindingRedirects.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 28
  • Comments: 24 (1 by maintainers)

Most upvoted comments

My apologies for the delay: https://gist.github.com/discodonut/d88279f956c1f353b96aab465f4eecf5

This has many caveats:

  • It will only run on Windows due to ILMerge
  • I have not tested the generated .dlls on any platform other than Windows
  • The version numbers are all hardcoded just to avoid breaking the script if something changes

This script was really meant to be a band-aid until this bug could be fixed, not a true fix.

FYI, downgrading to grpc_unity_package.2.26.0-dev is working without errors.

It is, but I was able to write a script that did this:

  1. Download Grpc and Google.Protobuf using the nuget command line tool, this pulls in dependent dlls.
  2. Copy out all netstandard2.0 dlls to into their own subfolder, one folder for all Grpc dlls, one for Google.protobuf dlls.
  3. Call ILMerge on each set of dlls with -internalize with exclude Grpc* and Google* respectively.

This will give you two new merged dlls, one for Grpc and one for Protobuf that can then be used in Unity. It does mean that you will essentially have multiple copies of the dependent dlls in your project. I’ll see if I can release the script I wrote, but I don’t see it as a good long-term solution, ILMerge is also Windows-only last I checked.

Same issue with the grpc_unity_package.2.29.0-dev and Unity 2019.3.5f1

Same issue with latest nightly (grpc_unity_package.2.29.0-dev) and unity 2019.3.0f6

when you say downgrading “the version used by Grpc”. What did you do here, as I’m coming across this error as well.