Announcement

Collapse
No announcement yet.

Important if you are using the Newtonsoft DLL in your plugin!

Collapse
This is a sticky topic.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • XboxMeister
    replied
    Thank you!

    Originally posted by bsobel View Post
    Here is an example form one of my plugins, it goes under configuration/runtime:

    <?xml version="1.0"?>
    <configuration>
    <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <probing privatePath="bin/CpsTuya"/>
    </assemblyBinding>
    </runtime>
    <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
    </startup>
    </configuration>

    Leave a comment:


  • bsobel
    replied
    Here is an example form one of my plugins, it goes under configuration/runtime:

    <?xml version="1.0"?>
    <configuration>
    <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <probing privatePath="bin/CpsTuya"/>
    </assemblyBinding>
    </runtime>
    <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
    </startup>
    </configuration>

    Leave a comment:


  • XboxMeister
    replied
    Originally posted by rjh View Post
    The following changes need to be made in order for your plugin to function properly with the HS3 version 3.0.0.333 or later.

    If you reference the Newtonsoft JSON DLL in your plugin, make sure you install that dll in your own folder. Lets assume your plugin is named "AcmePlugin", your install.txt should install the Newtonsoft dll to:

    bin\AcmePlugin

    You should then include a exe.config file with the bin path set like so:
    Code:
    <probing privatePath="bin/AcmePlugin;bin" />
    Note, many plugins are including the exe.config file and the bin path, but they are including "bin" before their own path, this is incorrect. Make sure "bin" is added after your private path.
    For this recommendation, where in the XML file structure does this need to be located? I added this to my app.config file in my VS project under the <startup> node but a Windows user had a problem getting the JSON DLL to be found when running the plug-in. Only after he moved the <runtime> section containing the probing statement up under <configuration> in the generated exe.config file did it find the DLL correctly (although I had no problem on my HS3 Windows PC using the exe.config file as it was). So does the probing line fall under <configuration>, <startup> or both? An example that shows more of the file would probably be helpful vs. just the single line.


    My original app.config file (probing just under <startup>)
    Code:
    <?xml version="1.0"?>
    <configuration>
      <system.diagnostics>
        <sources>
          <!-- This section defines the logging configuration for My.Application.Log -->
          <source name="DefaultSource" switchName="DefaultSwitch">
            <listeners>
              <add name="FileLog"/>
              <!-- Uncomment the below section to write to the Application Event Log -->
              <!--<add name="EventLog"/>-->
            </listeners>
          </source>
        </sources>
        <switches>
          <add name="DefaultSwitch" value="Information"/>
        </switches>
        <sharedListeners>
          <add name="FileLog" type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" initializeData="FileLogWriter"/>
          <!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
          <!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> -->
        </sharedListeners>
      </system.diagnostics>
      <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
        <runtime>
          <loadFromRemoteSources enabled="true" />
          <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <probing privatePath="bin/TankUtil" />
          </assemblyBinding>
        </runtime>
      </startup>
    </configuration>
    [LEFT][COLOR=#000000][FONT=Helvetica][SIZE=14px][/SIZE][/FONT][/COLOR][/LEFT]


    What he did to make it work and load the Newtonsoft DLL (relocated code in red)

    Code:
    [LEFT][COLOR=#000000][FONT=Helvetica][SIZE=14px]<?xml version="1.0"?>[/SIZE][/FONT][/COLOR][/LEFT]
    [LEFT][COLOR=#000000][FONT=Helvetica][SIZE=14px]<configuration>[/SIZE][/FONT][/COLOR][/LEFT]
    [COLOR=#FF0000][LEFT]    <runtime>[/LEFT]
    [LEFT]      <loadFromRemoteSources enabled="true" />[/LEFT]
    [LEFT]      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">[/LEFT]
    [LEFT]        <probing privatePath="bin/TankUtil" />[/LEFT]
    [LEFT]      </assemblyBinding>[/LEFT]
    [LEFT]    </runtime>[/LEFT][/COLOR]
    [LEFT][COLOR=#000000][FONT=Helvetica][SIZE=14px]  <system.diagnostics>[/SIZE][/FONT][/COLOR][/LEFT]
    [LEFT][COLOR=#000000][FONT=Helvetica][SIZE=14px]    <sources>[/SIZE][/FONT][/COLOR][/LEFT]
    [LEFT][COLOR=#000000][FONT=Helvetica][SIZE=14px]      <!-- This section defines the logging configuration for My.Application.Log -->[/SIZE][/FONT][/COLOR][/LEFT]
    [LEFT][COLOR=#000000][FONT=Helvetica][SIZE=14px]      <source name="DefaultSource" switchName="DefaultSwitch">[/SIZE][/FONT][/COLOR][/LEFT]
    [LEFT][COLOR=#000000][FONT=Helvetica][SIZE=14px]        <listeners>[/SIZE][/FONT][/COLOR][/LEFT]
    [LEFT][COLOR=#000000][FONT=Helvetica][SIZE=14px]          <add name="FileLog"/>[/SIZE][/FONT][/COLOR][/LEFT]
    [LEFT][COLOR=#000000][FONT=Helvetica][SIZE=14px]          <!-- Uncomment the below section to write to the Application Event Log -->[/SIZE][/FONT][/COLOR][/LEFT]
    [LEFT][COLOR=#000000][FONT=Helvetica][SIZE=14px]          <!--<add name="EventLog"/>-->[/SIZE][/FONT][/COLOR][/LEFT]
    [LEFT][COLOR=#000000][FONT=Helvetica][SIZE=14px]        </listeners>[/SIZE][/FONT][/COLOR][/LEFT]
    [LEFT][COLOR=#000000][FONT=Helvetica][SIZE=14px]      </source>[/SIZE][/FONT][/COLOR][/LEFT]
    [LEFT][COLOR=#000000][FONT=Helvetica][SIZE=14px]    </sources>[/SIZE][/FONT][/COLOR][/LEFT]
    [LEFT][COLOR=#000000][FONT=Helvetica][SIZE=14px]    <switches>[/SIZE][/FONT][/COLOR][/LEFT]
    [LEFT][COLOR=#000000][FONT=Helvetica][SIZE=14px]      <add name="DefaultSwitch" value="Information"/>[/SIZE][/FONT][/COLOR][/LEFT]
    [LEFT][COLOR=#000000][FONT=Helvetica][SIZE=14px]    </switches>[/SIZE][/FONT][/COLOR][/LEFT]
    [LEFT][COLOR=#000000][FONT=Helvetica][SIZE=14px]    <sharedListeners>[/SIZE][/FONT][/COLOR][/LEFT]
    [LEFT][COLOR=#000000][FONT=Helvetica][SIZE=14px]      <add name="FileLog" type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" initializeData="FileLogWriter"/>[/SIZE][/FONT][/COLOR][/LEFT]
    [LEFT][COLOR=#000000][FONT=Helvetica][SIZE=14px]      <!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->[/SIZE][/FONT][/COLOR][/LEFT]
    [LEFT][COLOR=#000000][FONT=Helvetica][SIZE=14px]      <!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> -->[/SIZE][/FONT][/COLOR][/LEFT]
    [LEFT][COLOR=#000000][FONT=Helvetica][SIZE=14px]    </sharedListeners>[/SIZE][/FONT][/COLOR][/LEFT]
    [LEFT][COLOR=#000000][FONT=Helvetica][SIZE=14px]  </system.diagnostics>[/SIZE][/FONT][/COLOR][/LEFT]
    [LEFT][COLOR=#000000][FONT=Helvetica][SIZE=14px]  <startup>[/SIZE][/FONT][/COLOR][/LEFT]
    [LEFT][COLOR=#000000][FONT=Helvetica][SIZE=14px]    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>[/SIZE][/FONT][/COLOR][/LEFT]
    [LEFT][COLOR=#000000][FONT=Helvetica][SIZE=14px]  </startup>[/SIZE][/FONT][/COLOR][/LEFT]
    [LEFT][COLOR=#000000][FONT=Helvetica][SIZE=14px]</configuration>[/SIZE][/FONT][/COLOR][/LEFT]
    [LEFT][COLOR=#000000][FONT=Helvetica][SIZE=14px][/SIZE][/FONT][/COLOR][/LEFT]

    Leave a comment:


  • XboxMeister
    replied
    Originally posted by shill View Post
    The exe.config file goes in the HS3 root directory along with your plugin exe file. The private bin folder is for any other DLLs you reference to avoid conflicts with other people using the same DLL but that might not always be the exact same version.
    Perfect! Thanks for the quick answer.

    Leave a comment:


  • shill
    replied
    The exe.config file goes in the HS3 root directory along with your plugin exe file. The private bin folder is for any other DLLs you reference to avoid conflicts with other people using the same DLL but that might not always be the exact same version.

    Leave a comment:


  • XboxMeister
    replied
    Hopefully a simple question on this requirement:

    I have the exe.config file generated by VS and have the string in it set as stated below for my plug-in. I can include it in my install zip file but where is it supposed to be installed in the directory structure? In my private bin folder next to the JSON DLL? Somewhere else? I'm going to try in my private bin folder but thought I'd ask while am working on it.

    Note, I am using this with my plug-in, not as part of any scripts so the ScriptingReferences stuff discussed in most of this thread doesn't apply I am pretty sure.

    thx

    XM

    Originally posted by rjh View Post
    The following changes need to be made in order for your plugin to function properly with the HS3 version 3.0.0.333 or later.

    If you reference the Newtonsoft JSON DLL in your plugin, make sure you install that dll in your own folder. Lets assume your plugin is named "AcmePlugin", your install.txt should install the Newtonsoft dll to:

    bin\AcmePlugin

    You should then include a exe.config file with the bin path set like so:
    Code:
    <probing privatePath="bin/AcmePlugin;bin" />
    Note, many plugins are including the exe.config file and the bin path, but they are including "bin" before their own path, this is incorrect. Make sure "bin" is added after your private path.

    Leave a comment:


  • shill
    replied
    And as I think I've mentioned before, the solution for all of us would be to expose that library directly so we can reference it from the hs object in both scripts and plugins, negating the need for so many different copies and potential for issues!

    Leave a comment:


  • shill
    replied
    I know this is several months old, but in case anyone else runs into this: you cannot use a scripting reference to a Newtonsoft.Json.dll file that doesn't match the one already loaded by HS3, even though it's not automatically exposed to scripts. If you're going to add a ScriptingReference, a) you don't need 8.3 or quotes - just type it out normally, and b) use the one in the bin\homeseer directory.

    Leave a comment:


  • scorp508
    replied
    Build 404

    Created a .\bin\NewtonSoftJson\ directory, copied the .DLL there.

    Set... ScriptingReferences=Newtonsoft.Json;C:\"Program Files (x86)\HomeSeer HS3"\Bin\Newtonsoft.Json.dll

    Resulted in...
    Jan-24 11:42:37 AM Error Compiling script Startup.vb: Illegal characters in path.

    I changed it to the 8.3 path format...

    ScriptingReferences=Newtonsoft.Json;C:\PROGRA~2\HOMESE~1\Bin \NewtonSoftJson\Newtonsoft.Json.dll

    This got rid of the illegal characters error at HS3 startup, but the script still fails with the following so I'm not sure what it's using. Maybe I'll fire up procmon later and see what file it is touching on the drive.

    Running script C:\Program Files (x86)\HomeSeer HS3\scripts\tankUtility.vb :Exception has been thrown by the target of an invocation.Could not load file or assembly 'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

    Leave a comment:


  • scorp508
    replied
    Build 404

    It would appear I'm now hitting a variation of this while trying to get a script from wpiman to work.

    I already have a Newtonsoft.Json.dll in .\HomeSeer HS3\bin\ that I didn't put it there myself. Something else did. When trying to run the script with the system as-is (newtonsoft.json.dll in .\bin\ and no ScriptingReferences entry) it errors saying the Json components were not imported.

    I then created ScriptingReferences=Newtonsoft.Json;Newtonsoft.Json.dll

    This wasn't enough, but also copying (not moving) Newtonsoft.Json.dll into .\HomeSeer HS3\ made the script work.


    Unfortunately, this also broke the ecobee and JowiHue plugins. Here's an error from JowiHue that looks like it did not like the version of Newtonsoft.Json.dll it was now seeing.


    Error: (UpdateBridgeCache):Is Bridge Philips hue reachable? Could not load file or assembly 'Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

    There are seven instances of Newtonsoft.json.dll in my entire homeseer directory structure.

    .\bin\ = v9.0.1.19813
    .\bin\weatherXML\ = v9.0.1.19813
    .\bin\homeseer\ = v8.0.3.19514
    .\bin\Z-Wave = v8.0.3.19514
    .\bin\Imperihome\ = v7.0.1.18622 (499KB) (Must be leftover files as this plugin is not installed.)
    .\bin\Ecobee\ = v7.0.1.18622 (508KB)
    .\bin\JowiHue\ = v7.0.1.18622 (499KB)

    Of the list above, both Ecobee and JowiHue share the same oldest common version of 7.0.1.18622. The one I copied into .\HomeSeer HS3\ was the v9.0.1.19813 from .\bin\ listed above.

    Removing ScriptingReferences from settings.ini wasn't enough to fix ecobee and JowiHue. It was the act of removing NewtonSoft.json.dll from .\HomeSeer HS3\ that repaired those plug-ins, yet made wpiman's script fail again.

    I'll try making a .\bin\newtonsoft\ directory and placing a copy in there, then pointing to it with ScriptingReferences and see what I get.

    Leave a comment:


  • bartbakels
    replied
    The build that you posted is indeed my production version, so 346

    Leave a comment:


  • rjh
    replied
    Did you try the latest beta build?

    The bin/homeseer folder is ignored when running scripts. I tested this by putting the newtonsoft dll in the bin/homeseer folder but then in scriptreferences I referenced a different sub folder for that dll and it failed, until I put the newtonsoft dll in the new folder.

    Originally posted by bartbakels View Post
    Rich,

    I found the issue...

    I replaced the newtonsoft dll in bin\homeseer with the version i needed for my scripts, this resolved the issue. Scripting reference still ste to bin\scripting\newtonsoft.json.dll.

    this means that the dll in bin\homeseer is used, so that the issue, the refrences are not being respected, prob due to the same name?

    However i dont get any errors now in HS3, and json commands still work, i dont know the influence the replacement of the json file has on HS3 itself?


    Bart

    Leave a comment:


  • bartbakels
    replied
    Rich,

    I found the issue...

    I replaced the newtonsoft dll in bin\homeseer with the version i needed for my scripts, this resolved the issue. Scripting reference still ste to bin\scripting\newtonsoft.json.dll.

    this means that the dll in bin\homeseer is used, so that the issue, the refrences are not being respected, prob due to the same name?

    However i dont get any errors now in HS3, and json commands still work, i dont know the influence the replacement of the json file has on HS3 itself?


    Bart

    Leave a comment:


  • bartbakels
    replied
    rich,

    any other things i can try?

    Bart

    Leave a comment:


  • bartbakels
    replied
    Originally posted by rjh View Post
    Not sure why the full path is not working. Can you remove the full path from the INI file then update to this build of HS3 and see if it works ok. Just put the part of the path where the file is like:

    bin\scripting\Newtonsoft.Json.dll

    This update to HS3 will automatically create the full path and add it to compiler as needed. It seems to work ok here.

    https://homeseer.com/updates3/SetupHS3_3_0_0_346.msi
    i tried this version

    but again;

    Code:
    jul-25 21:26:36	 	Error 1	Running script C:\Program Files (x86)\HomeSeer HS3\scripts\Domoticz Interface.vb :Exception has been thrown by the target of an invocation.Could not load file or assembly 'Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
    with this scripting ref;

    Newtonsoft.json;bin\scripting\Newtonsoft.Json.dll


    I tried also psmaaswinkels solution, with 346, which doesnt work for me either;

    Newtonsoft.json;C:\Program Files (x86)\HomeSeer HS3\bin\scripting\Newtonsoft.Json.dll

    and also

    Newtonsoft.json;C:\Program Files (x86)\HomeSeer HS3\bin\Newtonsoft.Json.dll

    same errors,


    but another thought. Its not the problem that it cant find the dll, because when i use an invalid path in the scripting reference i get other errors for all my scripts (compiler issues). looking to the error at hand, HS3 uses the wrong version of the newtonsoft dll so another dll is loaded when not located in the hs3 root.


    Bart
    Last edited by bartbakels; July 25, 2017, 02:48 PM.

    Leave a comment:

Working...
X