Announcement

Collapse
No announcement yet.

C# Referencing other assemblies

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    C# Referencing other assemblies

    I'm very frustrated by the lack of info on C# scripting.

    1) References to other DLLs. I've added to both ScriptingReferences in the settings.ini file and added the

    //css_reference System.Net to the script file (find this lame by the way).

    A script which was working just fine, now claims it can't find WebClient. I'm using HS3 3.0.0.280 on Windows.

    Is it possible to see what code is wrapped around the script? I know there is some because the line numbers don't line up.

    More info would be great.

    I know I could do this as a vb script but since I do C# for a living, I'd rather not have to keep switching gears.

    #2
    It's very likely that your settings.ini has a bad entry. That said, I think that HS generates the code in a Windows temp folder. On my unix platform, the .vb is created in /usr/tmp so I would suspect somewhere in the Windows ether there is a temp folder.
    HS4Pro on a Raspberry Pi4
    54 Z-Wave Nodes / 21 Zigbee Devices / 108 Events / 767 Devices
    Plugins: Z-Wave / Zigbee Plus / EasyTrigger / AK Weather / OMNI

    HSTouch Clients: 1 Android

    Comment


      #3
      It's not the settings.ini. It was working fine until the last day or so.

      Comment


        #4
        Yeah, not sure what would have changed on the HS side. Were you able to find the generated script? Can you post what you have and the error?
        HS4Pro on a Raspberry Pi4
        54 Z-Wave Nodes / 21 Zigbee Devices / 108 Events / 767 Devices
        Plugins: Z-Wave / Zigbee Plus / EasyTrigger / AK Weather / OMNI

        HSTouch Clients: 1 Android

        Comment


          #5
          Originally posted by rmasonjr View Post
          Yeah, not sure what would have changed on the HS side. Were you able to find the generated script? Can you post what you have and the error?
          Here is the script:

          //css_reference System.Net.dll;
          using System.Net;

          public object Main(object[] Parms) {
          const string WeatherURL = "http://www.weather.gov/xml/current_obs/KFIT.xml";
          const string ConditonsFile = @"D:\Users\Miles\Documents\Homeseer\Weather Data\CurrentConditions.xml";


          hs.WriteLog("GetCurrentWeather", "Getting current weather conditions from " + WeatherURL);

          try {
          WebClient client = new WebClient();
          client.Headers.Add("User-Agent", "HomeSeer/1.0");
          client.DownloadFile(WeatherURL, ConditonsFile);
          client.Dispose();
          hs.WriteLog("GetCurrentWeather", "Current weather conditions retrieved to " + ConditonsFile);
          }
          catch (Exception ex) {
          hs.WriteLog("GetCurrentWeather", "ERROR: Could not retrieve current weather:" + ex.Message);
          }

          return 0;
          }

          Here is the error:

          Compiling script P:\Program Files (x86)\HomeSeer HS3\scripts\UpTime.cs: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
          May-18 11:46:00 AM Error Compiling script P:\Program Files (x86)\HomeSeer HS3\scripts\GetWeatherForecast.cs: {interactive}(34,9): error CS0246: The type or namespace name `WebClient' could not be found. Are you missing a using directive or an assembly reference? {interactive}(36,9): error CS0841: A local variable `client' cannot be used before it is declared {interactive}(36,16): error CS0023: The `.' operator cannot be applied to operand of type `' {interactive}(38,9): error CS0841: A local variable `client' cannot be used before it is declared {interactive}(38,16): error CS0023: The `.' operator cannot be applied to operand of type `' {interactive}(40,9): error CS0841: A local variable `client' cannot be used before it is declared {interactive}(40,16): error CS0023: The `.' operator cannot be applied to operand of type `' {interactive}(9,17): warning CS0414: The private field `Script.hs' is assigned but its value is never used

          settings.ini has this:

          ScriptingReferences=System.Xml;System.Xml.dll,System.Globali zation;mscorlib.dll,System.Drawing;System.Drawing.dll,System .Net;System.Net.dll

          Comment


            #6
            Did not find the generated code.

            Comment


              #7
              I ran it here and it downloaded the file just fine.

              I think it might be something with your .NET installation?
              HS4Pro on a Raspberry Pi4
              54 Z-Wave Nodes / 21 Zigbee Devices / 108 Events / 767 Devices
              Plugins: Z-Wave / Zigbee Plus / EasyTrigger / AK Weather / OMNI

              HSTouch Clients: 1 Android

              Comment


                #8
                Do development on that machine all the time so I doubt it. Like I said, it just stopped working.

                Comment


                  #9
                  That script works here as well.

                  Code:
                  May-18 1:59:00 PM	 	GetCurrentWeather	Current weather conditions retrieved to c:\program files\homeseer hs3\data\CurrentConditions.xml
                  May-18 1:58:59 PM	 	GetCurrentWeather	Getting current weather conditions from http://www.weather.gov/xml/current_obs/KFIT.xml
                  May-18 1:58:09 PM	 	Event	Running script in background: c:/program files/homeseer hs3/scripts/test.cs
                  I have this in my settings.ini file:

                  Code:
                  ScriptingReferences=System.Management;System.Management.dll,System.Web;System.web.dll,System.Windows.Forms;System.Windows.Forms.dll,System.Drawing;System.Drawing.dll
                  Is perhaps System.Web needed for this?

                  Cheers
                  Al
                  HS 4.2.8.0: 2134 Devices 1252 Events
                  Z-Wave 3.0.10.0: 133 Nodes on one Z-Net

                  Comment


                    #10
                    Works here also, and curiously I have NO ScriptingReference: in my settings.ini

                    Z

                    Comment


                      #11
                      Very strange. If I take the script and turn it into a Windows console app (removing the hs.WriteLog calls). It works as expected. Clearly an issue with HS3 and not .NET. I need to see the generated final C# code.

                      Comment

                      Working...
                      X