Announcement

Collapse
No announcement yet.

Full C# Script

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

    Full C# Script

    I'm having trouble getting a C# script to run where I need to use a class from System.Net. The script is attached with a .txt extension.

    The error I get is:

    Compiling script P:\Program Files (x86)\HomeSeer HS3\scripts\GetCurrentWeather.cs: {interactive}(3,14): error CS1001: Unexpected symbol `(', expecting identifier {interactive}(3,35): error CS1530: Keyword `new' is not allowed on namespace elements {interactive}(3,38): error CS1001: Unexpected symbol `WebClient', expecting identifier {interactive}(1,2): warning CS0105: The using directive for `System.Net' appeared previously in this namespace

    It seems like the "using" statement is causing problems. However, if I remove it, I get all sorts of errors like this:

    Compiling script P:\Program Files (x86)\HomeSeer HS3\scripts\GetCurrentWeather.cs: {interactive}(4,6): error CS1525: Unexpected symbol `System', expecting `(' {interactive}(4,7): error CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement {interactive}(5,6): error CS1525: Unexpected symbol `System', expecting `(' {interactive}(5,14): error CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement {interactive}(6,6): error CS1525: Unexpected symbol `Scheduler', expecting `(' {interactive}(6,7): error CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement {interactive}(7,6): error CS1525: Unexpected symbol `HomeSeerAPI', expecting `(' {interactive}(7,7): error CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement {interactive}(8,0): error CS1525: Unexpected symbol `public', expecting `(' {interactive}(8,20): error CS1525: Unexpected symbol `{', expecting `(' {interactive}(10,2): error CS1525: Unexpected symbol `public' {interactive}(10,10): error CS1547: Keyword `void' cannot be used in this context {interactive}(10,20): error CS1525: Unexpected symbol `(' {interactive}(17,0): error CS1525: Unexpected symbol `public' {interactive}(17,8): error CS1547: Keyword `void' cannot be used in this context {interactive}(17,16): error CS1525: Unexpected symbol `(' {interactive}(31,5): error CS1524: Expected catch or finally {interactive}(44,4): error CS1525: Unexpected symbol `catch', expecting `catch' or `finally' {interactive}(48,4): error CS1525: Unexpected symbol `}', expecting `catch' or `finally' {interactive}(55,37): error CS8025: Parsing error

    Which include messages about HomeSeerAPI, Scheduler and more.

    I need to see what the full generated C# code is to try to make more sense of what's going on. If I take my script and wrap it in a normal C# environment (commenting out the hs.WriteLog statements), it runs just fine. I think something is wrong with my HS3 setup.

    I'm getting very frustrated by this as I've got a whole bunch of C# script work planned.

    Help please.
    Attached Files

    #2
    I'm not really a C# expert but I got this to work. Note the changes to the ConditonsFile declaration and getting rid of the "using" in the try.
    Attached Files

    Comment


      #3
      The string was just a C# string literal. https://msdn.microsoft.com/en-us/lib...(v=vs.71).aspx

      Get rid of the using in the try and you need to do a dispose. The using does that automatically.

      Think I'm going to do a reinstall of HS3. Something is messed up.

      Comment


        #4
        Thanks. Like I said I don't know much about C# so this is an opportunity for me to learn something new.

        I went back and added the literal (@) and it still works but when I try to put the using part back I get this:

        Compiling script C:\HomeSeer HS3\scripts\GetCurrentWeather.cs: {interactive}(5,18): error CS1001: Unexpected symbol `(', expecting identifier {interactive}(5,39): error CS1530: Keyword `new' is not allowed on namespace elements {interactive}(5,42): error CS1001: Unexpected symbol `WebClient', expecting identifier {interactive}(1,2): warning CS0105: The using directive for `System' appeared previously in this namespace {interactive}(3,1): warning CS0105: The using directive for `System.Net' appeared previously in this namespace

        I'm thinking this is a problem with however HS implemented the C# scripting rather than a reinstall issue. I will be interested to see your results.

        Comment


          #5
          Those are the types of errors I see. I didn't do a full reinstall, don't have the guts to do that yet. I did do a "repair". Made no difference.

          I definitely think it's on the HS side but just *crickets* from them. Apparently not many use it.

          Comment


            #6
            They appear to be using the script engine from http://www.csscript.net/. May provide some help but not sure.

            Comment

            Working...
            X