Issues with Vector3 referenced by shared library in C#

I am developing a FiveM gamemode in C# using Visual Studio, and I am trying to add a shared project called MyShared to share objects between the Server and Client code bases.

I have three .csproj in my solution - MyShared, Client, Server with references as follows:

MyShared
    - CitizenFX.Core.dll
Client
    - CitizenFX.Core.Client.dll
    - MyShared
Server
    - CitizenFX.Core.dll
    - CitizenFX.Core.Server.dll
    - MyShared

So in Client I am trying to use a class from MyShared which returns a Vector3, but it is complaining because the Vector3 returned is from Core.dll which is not referenced by the Client project:
The type 'Vector3' is defined in an assembly that is not referenced. You must add a reference to assembly 'CitizenFX.Core, Version=0.0.0.0

However if I add a reference to Core.dll to my Client project becomes a mess because Vector 3 is ambiguous across the two referenced .dlls (both Core.dll and Core.Client.dll).

How can I make the system understand that the Vector3 is simply the same thing regardless whether it comes from Core.dll or Core.Client.dll?

Thanks!

Hey, you can take a look on different public project made using C#
here an example : GitHub - frostylucas/fx-events: An event system made in C# for FiveM, for reference

I mean this is just an example, but you can find out multiple public project on github and take example from, just type fivem C# on github and then change the sort to recently update and here we go.

Thanks, but in that library the Shared library does not use any Vector3 or other class that comes from a CitizenFX .dll

My structure works functionally, but I am trying to make a definition of a game state which can be exchanged between client and server, that state contains a Vector3 which comes from CitizenFX.Core.dll

1 Like

Else you still have this tutorial, that can help you : [How-to] Setting up C# and creating a basic resource

1 Like

1 Like

Thank you for the replies, I looked again but unfortunately on GitHub I did not find any examples of a library shared across Client and Server which references Vector3.

You can just add an extra <Include /> to your .csproj to include shared logic - currently there’s no viable way to have the same assembly be used on client and server also as server will usually target netstandard.dll and client will target classic mscorlib.dll.

1 Like

Thanks, that’s a shame. Would you have any alternative suggestions for my use case?

In my shared project I have a “Race” definition made up of checkpoints (which contain Vector3 to define their positions). At the start of a race I send the race definition as a serialized JSON down to the client which parses it back to a class instance.

If the client knows the full state of the race they can do the calculations locally and simply do messages such as “Collect checkpoint 3” to move to the next checkpoint and re-render all the necessary entities on the client side.

I was hoping to be able to share the Race class that way I could use exactly the same methods on the Server and Client sides, depending on what I wanted from the race.

I have just tried making my own vector class and then using extension methods to convert it to client-type Vector3 and server-type Vector3, but it’s proving very tedious because I miss out on all the Vector3 methods. :sob:

Yeah, an Include with a shared directory should still be fine (in the csproj, like the official templates do).

1 Like