Newtonsoft

Discussion in 'Empyrion API' started by shadowpot, Jul 10, 2020.

  1. shadowpot

    shadowpot Ensign

    Joined:
    Jul 10, 2020
    Messages:
    3
    Likes Received:
    1
    I've been trying to get 3rd party dlls to load with the api but it's not working, I'ved added them to the mange folder and still a no go, Someone said I need to do an assembly load but I'm not to sure how to do that. I'm wanting to use newtonsoft so i can write data to a json and show it on a website.
     
    #1
  2. Khazul

    Khazul Rear Admiral

    Joined:
    Jan 15, 2020
    Messages:
    825
    Likes Received:
    1,445
    While not having done a mod for this, I vaguely remember a note about only a single assembly being supported. So, additional assemblies will have to be merged into a single assembly if that is the case using an appropriate tool.
     
    #2
  3. shadowpot

    shadowpot Ensign

    Joined:
    Jul 10, 2020
    Messages:
    3
    Likes Received:
    1
    I think i'm getting close. But I get this
    Code:
    11-15:24:23.587 10_24 -EXC- System.MissingMethodException: Default constructor not found for type Newtonsoft.Json.JsonConvert
      at System.RuntimeType.CreateInstanceMono (System.Boolean nonPublic) [0x0007b] in <567df3e0919241ba98db88bec4c6696f>:0
      at System.RuntimeType.CreateInstanceSlow (System.Boolean publicOnly, System.Boolean skipCheckThis, System.Boolean fillCache, System.Threading.StackCrawlMark& stackMark) [0x00009] in <567df3e0919241ba98db88bec4c6696f>:0
      at System.RuntimeType.CreateInstanceDefaultCtor (System.Boolean publicOnly, System.Boolean skipCheckThis, System.Boolean fillCache, System.Threading.StackCrawlMark& stackMark) [0x00027] in <567df3e0919241ba98db88bec4c6696f>:0
      at System.Activator.CreateInstance (System.Type type, System.Boolean nonPublic) [0x00020] in <567df3e0919241ba98db88bec4c6696f>:0
      at System.Activator.CreateInstance (System.Type type) [0x00000] in <567df3e0919241ba98db88bec4c6696f>:0
      at ServerStatus.Json.LoadNewtonSoftAssemby () [0x00087] in <37fa2ebd1cf44fbc9da29fa7d82cd2a0>:0
      at ServerStatus.ServerInfo.Game_Start (Eleon.Modding.ModGameAPI dediAPI) [0x0003f] in <37fa2ebd1cf44fbc9da29fa7d82cd2a0>:0
      at ModManager.Order (Eleon.Modding.ModGameAPI ) [0x00026] in <0ce5631c6d164269905ad1d036b92ecd>:0
    
    I know a little csharp but I haven't figured out all the names, I'm a self taught programmer, just say I know enough to do Harmony Patching. Got a few mods on nexus for a different game.
    Code:
    public static void LoadNewtonSoftAssemby()
    {
        Assembly a = Assembly.Load("Newtonsoft.Json");
        Type myType = a.GetType("Newtonsoft.Json.JsonConvert");
        MethodInfo myMethod = myType.GetMethod("SerializeObject", new Type[] { typeof(String) });
    //error is here
        object obj = Activator.CreateInstance(myType);
    //---------
        myMethod.Invoke(obj, null);
    }
    
    What i'm trying to do is get DediStats and PlayerInfo and put them in a Json file so I can show the data on a website. I got the DediStats Part working since I didn't need to use any list. PlayerInfo Data works but I'm trying to make a list for each player so JsonUtlity wasn't my best for that and I already have working code on newtonsoft for a list system.

    https://github.com/ihatetn931/Subna...ubnauticaBelowzeroMods/SubnauticaBZRP/json.cs
     
    #3
    Last edited: Jul 11, 2020
  4. Khazul

    Khazul Rear Admiral

    Joined:
    Jan 15, 2020
    Messages:
    825
    Likes Received:
    1,445
    If I remember correctly, JsonConvert is a static class and therefore has no constructors, so you cant create an instance of it. The specific error means the method you are trying to invoke does not exist (ie a default constructor does not exist).

    You only need to invoke the method without an instance - ie myMethod.Invoke(null, <your parameters>). null because there is no instance.
     
    #4
  5. ASTIC

    ASTIC Captain

    Joined:
    Dec 11, 2016
    Messages:
    993
    Likes Received:
    707
    #5
  6. shadowpot

    shadowpot Ensign

    Joined:
    Jul 10, 2020
    Messages:
    3
    Likes Received:
    1
    That worked, thanks appreciate it. Was much easier to get it working then I thought.

    This might be off topic but is there any documentation any where for the IModApi? I've only been able to find the legacy documentation.
     
    #6
    zaphodikus likes this.

Share This Page