Announcement

Collapse
No announcement yet.

Use Newtonsoft.Json.dll in C# script.

Collapse
X
 
  • 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.

    Code:
    //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
    Code:
    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 3.0.0.435
    Operating System: Microsoft Windows 10 Pro - Work Station
    System Uptime: 2 Days 1 Hour 12 Minutes 23 Seconds
    IP Address: 10.0.0.79
    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
    2.0.59.0: BLBackup
    3.0.0.21: Chromecast
    3.0.0.48: EasyTrigger
    3.9.610.5: HSBuddy
    3.0.0.28: ImperiHome
    3.0.2.0: MeiHarmonyHub
    0.0.0.42: Pushover 3P
    1.0.0.7: Restart
    30.0.0.36: RFXCOM
    3.0.8.4: SDJ-VStat
    3.0.1.190: Z-Wave

  • #2
    Anyone?

    Comment


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

      Take a read of this thread: https://forums.homeseer.com/forum/ho...lugin?t=189876
      Jon

      Comment


      • #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:
        Code:
        ScriptingReferences=Newtonsoft.Json;C:\PROGRA~2\HOMESE~2\Bin\NEWTON~1\Newtonsoft.Json.dll
        I found the path after using:
        Code:
        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.

        Comment


        • #5
          Even more fun:
          Code:
          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#?

          Comment


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

            Comment

            Working...
            X