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

Cant get this to compile in Unity 2022.3.14 #306

Open
adamgoodrich opened this issue Jan 5, 2024 · 6 comments
Open

Cant get this to compile in Unity 2022.3.14 #306

adamgoodrich opened this issue Jan 5, 2024 · 6 comments
Labels
help wanted Extra attention is needed

Comments

@adamgoodrich
Copy link

Observed behavior

Fails because of dependency on System.Text.Json.
The project is targeted at Android / .Net Standard 2.1. Mono.
I downloaded the .nuget package, unzipped it, and dropped the NATS.Client.Core DLL into the Plugins folder.

Expected behavior

It would be great to use the official library in Unity 3d. Perhaps I am doing something wrong.

Server and client version

I was using the latest Nats.Client.Core.2.0.2

Host environment

No response

Steps to reproduce

Add to unity project, try and use it.

@mtmk
Copy link
Collaborator

mtmk commented Jan 5, 2024

I've never used Unity before so I'm not sure. How would you even get net-6.0/8.0 targeted library to work with Unity? (I believe AlterNats was used in Unity projects and that was targeting net-6, so it must be possible)

Did you try adding System.Text.Json DLL as well?

https://www.nuget.org/packages/System.Text.Json

@mtmk mtmk added the help wanted Extra attention is needed label Jan 5, 2024
@adamgoodrich
Copy link
Author

adamgoodrich commented Jan 6, 2024

Yes, I did. That failed because of some weird incompatibility with Unity. I can't recall the error of the top of my head.

In the meantime I am using the v1 client, but I would prefer to use the latest and greatest here instead of doing all the threading / task management myself with v1.

I am wondering if someone else in the Unity community has managed to make this work.

@mtmk
Copy link
Collaborator

mtmk commented Jan 6, 2024

I did ask around but haven't heard back yet.

One thing I noticed is the target in Unity settings says netstandard 2.1. But we're targeting 6 and 8 at the moment. Having said that the AlterNats project (which we forked from) was targeting net6 as well and they used it for Unity.

When I tried I get a System.Runtime version mismatch error. How did you get pass that?

@adamgoodrich
Copy link
Author

adamgoodrich commented Jan 10, 2024

After doing a bunch of reading, and trying manually installing etc, i gave up and went back to the v1 library instead, and am using that in unity with no problems.

i also looked into installing all the code manually, and due to the way the basic code structures, I decided it was way too much work to refactor it all

just seems a shame not to be able to use the latest version.

not complaining :)

@mtmk
Copy link
Collaborator

mtmk commented Jan 10, 2024

Sorry about that @adamgoodrich it looks like we need to target netstandard-2.1. I gave it a go trying to see if it's easy enough but seemed like quite a bit of work. We quite consciously decided early on only to target .NET TLS releases maintenance overhead of other targets being one of the reasons.

Good news is there seems to be a way as Andrew Laing pointed out:
https://natsio.slack.com/archives/C1V81FKU6/p1704843867736829?thread_ts=1704450461.895889&cid=C1V81FKU6

Looks like AlterNats (parent fork) project was using MacigOnion RPC framework in between:
https://github.com/Cysharp/alternats?tab=readme-ov-file#architecture-guide

I believe this is the general idea:

                            gRPC                                NATS
[Unity + MagicOnion Client]------[MagicOnion Server + NATS.Net]------[NATS server]
      netstandard-2.1                   net6.0 / net8.0

Please let us know if this is a solution so we can suggest to other Unity devs.

@galvesribeiro
Copy link

Just a heads up - I've discussed briefly with @mtmk about Unity support. I'm going to push a PR to the .Net Client here soon that will unblock the latest version of the client to work with netstandard2.0 projects and that will allow us to use NATS client directly on Unity. Will also look into the possibility to make it more AoT friendly so it can work with scenarios like iOS and Android but this is just an attempt as I don't see NATS as being something publicly exposed to the internet for mobile clients but nonetheless, AoT support is good in general.

I'll link this issue to the PR when I get there in the following weeks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants