Example Visual Studio For Mac Building Backend Api Project

This is what I already have: 1. A template Visual Studio Web API project with mixed C#, which calls some sample C++ code. Some C++ classes which provides step-by-step instructions to solve a Sudoku puzzle.

Active15 days ago

Here, or here for a complete version, you can find a sample GRPC 'Hello World' project for Unity. Only the first version, that is built for Unity and wrapped in a DLL is working perfectly fine in Unity IDE and on Standalone build. The Raw Grpc.Core files are referencing everything correctly in IDE but they have Marshaling problem.

Unfortunately, it cannot get build for UWP with IL2CPP backend. Unity builds the project and creates a .sln project. But Visual Studio always gives LNK2001 for GRPC properties on the final compilation.

Here are first error codes:

Code

Ok, thanks to @Sunius, I digged into it a little bit more. There are some points, I am going to add to the question:

There are two methods regarding referencing extern methods in GRPC C# package. They are named static and shared libs.

and

I tried to test it with the shared one, I got another linking error file which is a little bit different.

In two separate methods, extern methods are getting connected to the internal interface:

and

And which method will get called is defined here:

Example Visual Studio For Mac Building Backend Api Project Fitness

Some updates:

Thanks to @jsmouret, there is Stub.c file in his Grpc Github with fake methods, so Linker does not complain about Grpc_init methods anymore.

Next Error: dlopen, dlsym, dlerror:

First, I tried to use the same, Stub technique, but it did not help in this case, or maybe I did it wrong.

Download Microsoft Visual Studio For Mac

Thanks to @Sunius, I commented out all of '__Internal' dll import codes. So I am not getting any dlopen, dlsym, and dlerror errors.

Next Error: It happens from inside application, not the visual studio debugger. It tells me: 'exception: to marshal a managed method, please add an attribute named 'MonoPInvokeCallback' to the method definition.'

and

After I googled it, I know my options, but the question it, for which method should I do that?!

Mohsenne
MohsenneMohsenne

2 Answers

Thanks to my colleague Alice, @Sunius and @jsmouret, at the end, grpc works on UWP on Unity Platform through this steps:

  1. Download Grpc.Core folder from Google Grpc Github.
  2. Download Grpc Unity plugin from their official site.
  3. Copy the runtime folder to your Grpc.Core folder. Please remove Grpc.Core.dll that you get from Grpc Unity Plugin, since we are using their source code.
  4. Grpc should be in a folder called, Plugins in Unity, otherwise it will not be recognized.
  5. Include this file in your runtime folder.
  6. Include the Stub also from the Unity Plugin Inspector for WSA.
  7. Find runtime .dll for Windows and include them in WSA from Unity Plugin Inspector.

By now, you should be getting _dlopen error.

  1. Search through your Unity Solution with an IDE for '__Internal'. There are not so many places, but comment them out. Also some methods that are depended on '__Internal's, like dlopen and dlsym.

By now, you are not getting anymore build error but you need to make Grpc work.

  1. Search for something like 'DefaultSslRootsOverride' and comment out like below:

  2. Search for something like 'static void HandWrite' and add an attribute like something in below:

I guess, you are done. In case, it did not work for your UWP, let me know, maybe I can help. :)

MohsenneMohsenne

Visual Studio

It looks like your plugin uses '__Internal' P/Invoke to call those native functions:

However, the linker cannot locate those functions and thus fails. You should change that code to either specify the DLL file name where the functions are implemented, or drop the source files with definitions for those functions into your Unity project. Or, if that code path isn't actually invoked (since you said it works on the standalone player), #ifdef it out from UWP build.

You can find more information about '__Internal' P/Invoke here:

SuniusSunius

protected by ZoeAug 23 at 14:01

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged visual-studiounity3duwpgrpcil2cpp or ask your own question.