[SOLVED] Exports with C# using FxDK (FiveM)

First time posting here so sorry if this is the wrong area. I have been working with c# for a while so I know the syntax and I know how to work with class libraries with normal projects. Anyway my question is how do I reference other resources. for example usually you would do something like

namespace MyResourceName
{
    public class Config
    {
        public static string myString;
       public static int myInt;
    }
}

then you would build that and reference the dll in the other script and do something like

using MyResourceName;

public class MyOtherResource
{
    public void main()
    {
        string myString = Config.myString;
        int myInt = Config.myInt;
    }
}

This obviously does not work with FiveM. I’m aware you are suppose to do something with exports… but I have been unable to figure this out. What I am trying to do is have a core resource that holds all the main config and reference that resource from other resources.

EDIT:
I’ve been messing around with stuff and i think I have come to the conclusion that my issue is to do with an error that I’m pretty sure is on the FxDK side

Error: There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "C:\Users\****\.nuget\packages\citizenfx.core.server\1.0.5054\lib\netstandard20\CitizenFX.Core.Server.dll", "AMD64". This mismatch may cause runtime failures.

This error is causing compiler issues which I’m pretty sure is what is casing issues with exports in c#.
if I try opening the project in visual studio 2017 the recommended version on the docs its just causes even more issues so not quite sure how to go about fixing it.

EDIT 2:
I seem to have figured out how to fix the above error by adding

<PlatformTarget>x64</PlatformTarget>

to the .csproj file
so original that FxDK generates looks something like this for the client

<Project Sdk="CitizenFX.Sdk.Client/0.2.2">
  <ItemGroup>
      <Compile Include="../Shared/**/*.cs" />
  </ItemGroup>
</Project>

I changed it to this and the error has stopped appearing

<Project Sdk="CitizenFX.Sdk.Client/0.2.2">
  <ItemGroup>
      <Compile Include="../Shared/**/*.cs" />
  </ItemGroup>
  <PropertyGroup>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
</Project>

I also added the platform target to the server csproj file as well and everything seems to be working correctly… now back to trying to figure out the exports stuff.

solution:

1 Like

Huh- this is usually a warning. Where are you getting this shown as an error?

in the FXDK editor wen I create a new resource and then enable restart on change wen ever I click on a script for example if I click on the clientscript.cs it will pop up a box in the bottom corner telling me this… the warning will also continuously pop up every time I try to open a script or rebuild things.

so it shows as a warning at the bottom as you can see but then clicking on it brings up the console were it says its an error and may causes runtime issues…

my “fix” gets rid of this warning and seems to have everything working fine

Ah, OmniSharp doesn’t like that: makes sense.

Since a recent Mono update I think setting stuff as x64 works fine nowadays so maybe changing the default is safe, though I’d rather prefer making the reference assembly not marked as AMD64 so old projects will be fine as well.

Do you think I should post that as a bug? because as far as I’m aware you can not change default architecture in FXDK… other then manually editing the .csproj file.

Ok so after many hours of hitting my head on the keyboard I have come up with a solution for exports and c#. Not sure if this is the most efficient way of doing things but its what I have working.

MyResourceOne

using CitizenFX.Core;
using System;
using System.Dynamic;

public class CoreConfig : BaseScript
{

public delagate dynamic playerBloodtypeDelagate();
    
public CoreConfig()
{
    playerBloodtypeDelagate playerBloodTypes = 
             new playerBloodtypeDelagate(PlayerBloodTypes)

    try
    {
       RegisterExport("GetPlayerBloodtypes" , 
               playerBloodTypesDelagate);
    {
    catch(Exception ex)
    {
        Debug.writeline("Error::: " + ex.message);
    }
    
}

public static dynamic PlayerBloodTypes()
{
    dynamic bloodTypes = new ExpandoObject();
    bloodTypes.Aplus = "A+";
    bloodTypes.Aminus = "A-";
    return bloodTypes;
}

public void RegisterExport(string _export, Delegate _delagate)
{
    try
    {
        Exports.Add(_export, _delagate);
     }
    catch (Exception ex)
    {
       Debug.WriteLine("Error::  " + ex.Message);
    }
}

}

and to get the player bloodtypes from this resource you would do this

MyOtherResource

using System;
using System.Threading.Tasks;
using CitizenFX.Core;

public class MyOtherResource : BaseScript
{
    public MyOtherResource()
    { 
         var playerBloodtypes = 
               Exports["MyResourceOne"].GetPlayerBloodtypes();

        Debug.Writeline(playerBlodtypes.Aplus);
    }

}

the output of the second resource is A+

as i said before idk if this is the most efficient way of doing things but works well enough… if anyone has any ideas on how to improve this or a better way of doing this please let me know.

Hey @Mecanim, question, is that supposed to say Debug.Writeline(playerBlodtypes.Aplus) or Debug.Writeline(playerBloodtypes.Aplus)? Just thought I’d help if you didn’t notice.

Debug.WriteLine(playerBloodtypes.Aplus);

keep in mind inteli-sense wont auto complete with the Exports like it normally would wen referencing stuff in C#… so you need to know exactly what you are referencing.

Hey, its probably a bit late, but what exactly did you write in you fxmanifest for the exports, or is this not needed for c# ?