Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReadOnlySequence<> Error #14

Open
Shantibhushan95 opened this issue Sep 10, 2020 · 8 comments
Open

ReadOnlySequence<> Error #14

Shantibhushan95 opened this issue Sep 10, 2020 · 8 comments

Comments

@Shantibhushan95
Copy link

I added all the stated dlls into the Assets folder root and that got rid of all the missing references except for this one. Tried different System.Memory versions to no avail. Any leads?

Library\PackageCache\com.e7.protobuf-unity@2956da0\Runtime\ProtoBinaryManager.cs(40,38): error CS0012: The type 'ReadOnlySequence<>' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Memory, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.

@daviderickson
Copy link

I'm having the same issue.

@daviderickson
Copy link

Looks like it is an issue with Protobuf 3.13.x, I used the following NuGet package versions for .net2.0 target and it worked for me:

Protobuf 3.12.4
System.Buffers 4.5.1
System.Memory 4.5.4
System.Runtime.CompilerServices.Unsafe 4.7.1

Maybe the author can at least document, or ideally investigate a solution for 3.13.x?

@daviderickson
Copy link

Looks like it is an issue with Protobuf 3.13.x, I used the following NuGet package versions for .net2.0 target and it worked for me:

Protobuf 3.12.4
System.Buffers 4.5.1
System.Memory 4.5.4
System.Runtime.CompilerServices.Unsafe 4.7.1

Maybe the author can at least document, or ideally investigate a solution for 3.13.x?

I spent more time trying to get GRPC working with the above versions and couldn't manage it. But I did find a unity-specific build of GRPC 2.26 that contained all the assemblies and works great: https://packages.grpc.io/archive/2019/12/a02d6b9be81cbadb60eed88b3b44498ba27bcba9-edd81ac6-e3d1-461a-a263-2b06ae913c3f/index.xml

I used protoc 3.10.1, and the nuget grpc.tools grpc_csharp_plugin.exe 2.26.0 with the above.

@louis030195
Copy link
Contributor

louis030195 commented Dec 18, 2020

Looks like it is an issue with Protobuf 3.13.x, I used the following NuGet package versions for .net2.0 target and it worked for me:

Protobuf 3.12.4
System.Buffers 4.5.1
System.Memory 4.5.4
System.Runtime.CompilerServices.Unsafe 4.7.1

Maybe the author can at least document, or ideally investigate a solution for 3.13.x?

These are good versions, in my case running Unity 2020.2.0f1:

  • Google.Protobuf 3.12.3
  • System.Runtime.CompilerServices.Unsafe 4.5.2
  • System.Buffers 4.4.0
  • System.Memory 4.5.2
  • System.Numeric.Vectors 4.4.0

When you upgrade your Unity version it can make conflict with System.Memory which is used by com.unity.collections (I'm not 100% sure on this one but had a problem with that someday)

When you use Protobuf check properly you code stripping parameters either in the IDE or as code because Unity strip Protobuf dependencies for example with high level of stripping for more detail see Unity doc, also IL2CPP builds strip code by default so don't be surprised if you have errors while you have set stripping to "none"

PlayerSettings.SetManagedStrippingLevel(BuildTargetGroup.Standalone, somelevel);

I used this to fix my IL2CPP WebGL build which stripped Protobuf

<linker>
    <assembly fullname="Google.Protobuf" preserve="all"/>
</linker>

Overall using Protobuf with Unity is a pain, made me lost lot of time, BUT once it works, it's really nice and you don't have tons of c# OOP classes junks everywhere and for server side it's awesome, I use Nakama which uses Go, Protobuf is super nice in Go !

RyouBakura added a commit to RyouBakura/protobuf-unity that referenced this issue Mar 14, 2021
@RyouBakura
Copy link
Contributor

RyouBakura commented Mar 14, 2021

Add System.Memory.dll to the runtime .asmdef:

Unity_j2r9TxAgl3

@gardenofnumbers
Copy link

This above solved my issue! I installed the latest versions of the four packages from Nuget. I also opened the visual studio project and added an assembly reference, although this allowed it to build in VS but did not solve the problem on the unity end.

I was finally able to build in unity by modifying the asmdef for E7.ProtobufUnity as above

@5argon
Copy link
Owner

5argon commented Sep 18, 2021

I should have edit the document soon, yes, newer Protobuf DLL (around the time it started supporting .NET Standard) uses more .NET features that is not included by default in Unity. Unfortunately, that may means something in the generated Protobuf code may not work or only works partially (e.g. not on all platforms Unity supported, so they can't guarantee including it.)

I have scanned through versions and here are all the "breakpoints", which is the highest version before the next one changed requirement of library reference.

These means under .NET 4.x settings 3.10.1 is likely the most "Unity-friendly" version of DLL. I am not sure which protoc version will generate a C# code matching this version.

For .NET Standard 2.0 the first one 3.10.1 already requires System.Memory, and will in turn require System.Buffers (>= 4.4.0), System.Numerics.Vectors (>= 4.4.0), System.Runtime.CompilerServices.Unsafe (>= 4.5.2). For Standard 2.0 you should go all the way to the latest one, it is the same requirement.

But at the same time, you would need protobuf generator of around the same version or else it would generate code that use unreferenced DLL. Then that way, you maybe not missing just features but also bug fixes.. so choose at your own risk.

3.7.0

.NETFramework 4.5

No dependencies.

.NETStandard 1.0

NETStandard.Library (>= 1.6.1)

3.10.1

.NETFramework 4.5

No dependencies.

.NETStandard 1.0

NETStandard.Library (>= 1.6.1)

.NETStandard 2.0

System.Memory (>= 4.5.2)

3.12.4

.NETFramework 4.5

System.Memory (>= 4.5.2)

.NETStandard 1.0

NETStandard.Library (>= 1.6.1)

.NETStandard 2.0

System.Memory (>= 4.5.2)

3.18.0 (Latest)

.NETFramework 4.5

System.Memory (>= 4.5.3)

.NETStandard 1.1

NETStandard.Library (>= 1.6.1)
System.Memory (>= 4.5.3)

.NETStandard 2.0

System.Memory (>= 4.5.3)
System.Runtime.CompilerServices.Unsafe (>= 4.5.2)

net5.0

No dependencies.

@miltoncandelero
Copy link

miltoncandelero commented Sep 12, 2023

Just in case another poor soul like me shows up:

Results:
Editor: Parsing + ToString() Ok
Android: Parsing + ToString() Ok
WebGL: Parsing + ToString() Ok
iOS: Parsing + ToString() Ok

No reflection error or anything like that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants