No announcement yet.

Use Newtonsoft.Json.dll in C# script.

  • Filter
  • Time
  • Show
Clear All
new posts

  • Use Newtonsoft.Json.dll in C# script.

    This is the simplest script I could come up with trying to use the library. I have tried many different variants for this without luck. Since there is hardly any documentation on this (as far as I have found), I copied the Newtonsoft.Json.dll to the scripts directory of Homeseer.

    //css_searchdir "C:\Program Files (x86)\HomeSeer HS3\scripts";
    //css_reference Newtonsoft.Json.dll;
    //css_import Newtonsoft;
    using Newtonsoft;
    using Newtonsoft.Json;
    using Newtonsoft.Json.JsonConvert;
    public object Main(object[] param)
      var someJson = "{}";
      var result = Newtonsoft.Json.JsonConvert.DeserializeObject(someJson);              
      hs.WriteLog("Test-Script", "Worked");
      return 0;
    The error I am getting
    Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\CSharpTest.cs: {interactive}(36,16): error CS0103: The name `Newtonsoft' does not exist in the current context {interactive}(36,27): error CS0023: The `.' operator cannot be applied to operand of type `' {interactive}(36,3): error CS0825: The contextual keyword `var' may only appear within a local variable declaration {interactive}(13,17): warning CS0414: The private field `Script.hs' is assigned but its value is never used
    System info:
    Current Date/Time: 26/07/2018 11:31:56 PM
    HomeSeer Version: HS3 Pro Edition
    Operating System: Microsoft Windows 10 Pro - Work Station
    System Uptime: 2 Days 1 Hour 12 Minutes 23 Seconds
    IP Address:
    Number of Devices: 302
    Number of Events: 21
    Available Threads: 200
    HSTouch Enabled: True
    Event Threads: 0
    Event Trigger Eval Queue: 0
    Event Trigger Priority Eval Queue: 0
    Device Exec Queue: 0
    HSTouch Event Queue: 0
    Email Send Queue: 0
    Anti Virus Installed: Windows Defender

    Enabled Plug-Ins BLBackup Chromecast EasyTrigger
    3.9.610.5: HSBuddy ImperiHome MeiHarmonyHub Pushover 3P Restart RFXCOM SDJ-VStat Z-Wave

  • #2


    • #3
      You need to add an entry to the ScriptingReferences entry in Settings.ini.

      Take a read of this thread:


      • #4
        From my understanding from reading the docs that should only be needed for VB scripts, or? Anyway I tried to add this to the settings.ini file:
        I found the path after using:
        for %I in (.) do echo %~sI
        from my folder. I am confident that this worked, since I got error messages during startup when the path was incorrect.

        But this did not solve anything, I still have the same error message from my simple script.


        • #5
          Even more fun:
          Imports Newtonsoft
          Public Sub Main(ByVal Parms As Object)
              Dim json = "{}"
                  Dim res  = Newtonsoft.Json.JsonConvert.DeserializeObject(json)
                  hs.WriteLog("json VB", "worked") 
          End Sub
          This worked fine... so whats up with C#?


          • #6
            Try "Using" in place of "Imports"