OpenAvikom / mr-grpc-unity

Use gRPC to send protocol buffer messages from and to Unity
16 stars 5 forks source link

Can't find grpc assemblies from script #1

Open fmatulic opened 2 years ago

fmatulic commented 2 years ago

I copied your Plugins folder in the Assets folder of my project but my script can't find the assemblies and I get several errors like this: The type or namespace name 'Google' could not be found in the global namespace (are you missing an assembly reference?)

What could be the problem?

aleneum commented 2 years ago

Hello @fmatulic,

seems like your Google.Protobuf or Google.Api.CommonProtos dependency (found in the Plugins-Folder) is not loaded correctly.

fmatulic commented 2 years ago

That's what the error message indicates, yes. The question is why. As per the instructions, I copied the content of UnityGRPC/Assets/Plugins to the Plugins folder of my project and link.xml to Assets. The only thing I wasn't quite sure about is "Make sure that all DLL targets in Grpc.Core/runtimes/win/<arch> are correctly set". If that means setting the correct platform for the three grpc_csharp_ext.dll in the inspector, I've checked that that's the case.

aleneum commented 2 years ago

I cannot really say what's going wrong. Maybe checkout the whole sample project and try to load it with Unity. This should work. If it doesn't, there might be incompatibilities with your version of Unity.

fmatulic commented 2 years ago

It doesn't. The Hello class in the proto folder is unable to find the namespace Google. I'm using the latest version of Unity 2020, i.e. 2020.3.25f1.

aleneum commented 2 years ago

I just downloaded 2020.3.25f1 (with UWP and IL2CPP Modules), cloned the project and it works fine. I can run HelloGRPC without issues. What's your platform? Do you use a *nix by any chance?

fmatulic commented 2 years ago

No, I'm on Windows 10.

So let me outline the steps I take to reproduce the problem. I don't know, maybe I'm doing something wrong.

Here's the screen I get: image

aleneum commented 2 years ago

Does Unity mention some issues related to Google.Protobuf.dll?

grafik

fmatulic commented 2 years ago

My screen is somewhat different from yours, but I don't see any problem reported about Google.Protobuf.dll either in the inspector or in the console.

image

aleneum commented 2 years ago

I launch the project, but after a while I'm prompted to go into Safe Mode because there are some errors, specifically the Google and Grpc namespaces which can't be found in the scripts.

I assume the "after a while" reads as "when the compile attempt failed". It doesn't work first and suddenly stops working, does it? "Google and Grpc namespaces which can't be found in the scripts." That is correct since they are part of the mentioned DLLs in the Plugin Folder. I am still not convinced that Unity is loading these DLLs correctly... Maybe there are issues with your (default) player settings. Maybe setting the Api Compatibility Level to Net 4.x (Player -> Other Settings) is required. It does work for me without this change though.

I cannot really debug that for you remotely, sorry. I would suggest to 'divide and conquer' the issues here. Check whether you can get protobuf to work in a simple project. I am not sure whether NuGetForUnity already supports Unity 2020 flawlessly but usually that's the easiest way to add Google.Protobuf to a Unity project. Proto\Hello.cs should work without gRPC and compile successfully when Google.Protobuf is available. You could also try whether using Unity 2019 makes a difference.

fmatulic commented 2 years ago

"After a while" means while Unity is importing files on startup and presumably trying to compile the scripts, yes. Setting the API compatibility level to .NET 4.x or switching to Unity 2019 didn't solve the problem.

I've successfully tested the Unity package of the official GRPC C# release in my environment. If works flawlessly on my Windows desktop, but of course, not on ARM64 devices.

aleneum commented 2 years ago

Hmm.. unfortunately I am out of ideas. You could try to compile the necessary libraries yourself as outlined in this issue. But Google.Protobuf has not been manually compiled and should work independently of the gRPC plugins.

fmatulic commented 2 years ago

That's exactly what I ended up doing. I followed the instructions given here and it works, but unfortunately without SSL.

aleneum commented 2 years ago

@fmatulic: Since the C# implementation of GRPC is in maintenance mode, grpc-dotnet is probably the better target for new projects. Last time I checked (which was roughly beginning/mid of last year), Unity did not support the required net-core versions. But this post looks like that this has been solved. If you give it a try, let me know and I will update this example to use more recent gRPC versions.

HaiKonofanDesu commented 1 year ago

Sooo.. I have the same problem as @fmatulic with the same errors. Sadly I can't do what is written in the comment that he linked because I get a timeout for Google/RE2 when running submodule update --init -> Make the build later not possible. You have any tips/ can you share your compiled files somehow?

@aleneum any updates on this? In my private project I used a combination of different plugins to get no errors in the Unity Editor but the moment I try to compile it for HoloLens 2 I get an error "The type or namespace name 'Channel' could not be found (are you missing a using directive or an assembly reference?)" -> is this somehow missing in your .dll? You use the same command but apparently it works for you... Tried it with Unity 2021 and 2020 and I'm at the point where I have no idea how i can get it working...

About the gRPC.NET stuff -> It requires Http/2 which is not supportet on HoloLens 2? I got it running in Unity but sadly not on the HoloLens (can compile it and all but not sucessful connection) so I appreciate ANY help. I'm down to do Teams calls or so as well if this helps someone.

fmatulic commented 1 year ago

I have the same problem as @fmatulic with the same errors. Sadly I can't do what is written in the comment that he linked because I get a timeout for Google/RE2 when running submodule update --init -> Make the build later not possible. You have any tips/ can you share your compiled files somehow?

Not sure if that last question/request is addressed to me. You'd like me to share my manually compiled grpc binaries?

HaiKonofanDesu commented 1 year ago

@fmatulic Sorry for the late reply, was a busy Weekend. If possible I whould Love a .zip file with all the Grpc Stuff in there.

Seems like I actually got the files compiled myself now. At least an empty project with just these files works just fine to build and deploy.

But I still get an error when I try to deploy my stuff to the HoloLens:

image

Any ideas how to fix it?

EDIT: Seems like the problem are my generated .cs files (from the .proto files). Can someone eplain in more details how they generated their files? dotnet build csharp did not work for me. I instead did it like it's descibed here: https://shadabambat1.medium.com/basic-client-server-communication-using-unity-grpc-f4a3c2cf819c

fmatulic commented 1 year ago

I'm not sure I can help you with the compile errors you get with your code, but here are my grpc dlls, anyway. I put those files in a "Plugins" folder under Assets. Then, you need to make sure the platform settings are correct for each version of the DLLs in the inspector. GRPC-Unity.zip

I don't remember having any particular issues when generating my stubs with protoc and compiling them.

HaiKonofanDesu commented 1 year ago

@fmatulic thanks! I Check the zip Out later.

So far the Error seems to be a Unity 2021 Problem. Rebulding my project for Unity 2020 worked fine. Sadly I can't listen with my HoloLens to my server I always get the "can't connect to all URLs" Error. Not sure if it's a firewall error or problem with my gRPC DLL stuff.

EDIT: Seems like the whole Grpc.Core Folder is missing from your .zip? Is it not needed with your build? Will Update this post once I tested the Connectopn to my private PC to check if the Firewall is a problem