Announcement

Collapse
No announcement yet.

Type of namespace name does not exist

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

    #16
    alexbk66 sorry, I was confused about fuslogwv.exe because it comes with the MS SDKs.
    • I am running it in admin mode (right click, run as administrator).
    • I have exactly the same setting and c:\temp is a directory that exists (see screenshot below)
    • I close the settings dialog box before proceeding
    • I then run my event that calls the script.
    • I then go to the HS log file to see I still get the compiler error, which I do.
    • I then go back to fuslogwv.exe and hit "Refresh" but nothing shows up. Not log file is written to c:\temp, either.

    I suspect that I don't see anything in fuslogwv.exe because my script never gets to the point of running. The problem is that HS doesn't even finish compiling the script as seen in my post Albums


    Click image for larger version  Name:	logSettings1.png Views:	0 Size:	27.8 KB ID:	1611349
    Attached Files

    Comment


      #17
      Originally posted by tenholde View Post
      I've been out of town, but will try and look at this tonight or tomorrow. In the meantime, this might help:

      https://tenholder.net/tenWare2/HsTop...rpScripts.aspx

      I've never been able to get the //css.reference statements to work.
      tenholde I read through your link. So I am keeping these extremely simple.
      • If I comment out the System.Drawing.Bitmap bitmap; then everything compiles file (doesn't do anything but no errors)
      • If I leave System.Drawing.Bitmap bitmap; in then I get the error listed below.
      • People suggested that System.Drawing has MS specific stuff in it so I should use System.Drawing.Common. So I tried the same as in the code below but with System.Drawing.Common.Bitmap. I also adjusted the using statement and copied the System.Drawing.Common.dll into various folders incl. c:\Program files(x86\HomeSeer HS4 and subfolder script and a few other subfolders (I gradually did that, not all at ones).
      • In settings.ini on the last section for the [settings] section (before the [display] section) I added ScriptingReferences=System.Drawing.dll. I also tried the variant with common. I still get the same error.
      • In some other thread I found that when something is wrong in settings.ini entries below it won't be processed. So I also put the ScripptingReferences as the first line right after [Settings]. Still the same problem.
      Do we know if that the code HS creates (where it embeds our scripts) is stored on disc somewhere? Also for ScripptingReferences do I need to provide the full path? I am just not sure what path because there are multiple different versions of the same dll. I would think Windows will figure out which one to pick, i.e. don't give a specific path (and if windows picks the wrong one it would blow up when running and not during compilation).

      Code:
      using System.Drawing;
      
      public void Main(object argument)
      {
         System.Drawing.Bitmap bitmap;​
      }
      Click image for larger version

Name:	CompileError1.png
Views:	109
Size:	16.1 KB
ID:	1611351

      Comment


        #18
        FYI, unless you can define the scripting references correctly, this is never going to work.

        As Tenholde states, he and other people have never been able to get references working by using //css.reference statements in C# scripts. You cannot use the ScriptingReferences entry in settings.ini as that is for VB.Net scripts only.

        One option would be to convert your script to VB.Net.
        Jon

        Comment


          #19
          I thought ScriptingReferences in settings.ini is working now also for c#. I read something like that on the forum and according to tenholde website

          " Existing HS documentation still states that the ScriptingReferences entries are only used for VB scripts and do nothing for C# scripts, but since HS version 4.2.11, this is not longer correct. An example:

          ScriptingReferences=tenGlobalMethods;tenGlobalMethods.dll,Sy stem.Data.SQLite;bin\homeseer\System.Data.SQLite.dll​"

          Comment


            #20
            Originally posted by mulu View Post
            I thought ScriptingReferences in settings.ini is working now also for c#. I read something like that on the forum and according to tenholde website

            " Existing HS documentation still states that the ScriptingReferences entries are only used for VB scripts and do nothing for C# scripts, but since HS version 4.2.11, this is not longer correct. An example:

            ScriptingReferences=tenGlobalMethods;tenGlobalMethods.dll,Sy stem.Data.SQLite;bin\homeseer\System.Data.SQLite.dll​"
            That is correct. I worked with Rich to have this implemented
            tenholde

            Comment


              #21
              Originally posted by tenholde View Post

              That is correct. I worked with Rich to have this implemented
              Good to know!
              Jon

              Comment


                #22
                So a year later I am still struggling with this... This time I took System.Drawing.Bitmap out of the loop and wrote a very simple dll using .NET Framework 4.0. All that is in the code is

                Code:
                namespace ExternalDllTest {
                    public class TestClass {
                        public double Add(double in1, double in2) {
                            return in1 + in2;
                        }
                    }
                }​
                The dll is in the attached zip file. It's compiled in debug mode and shows everything in ILSpy.

                Click image for larger version  Name:	ILSpy1.png Views:	0 Size:	102.5 KB ID:	1666304
                I copied the dll into C:\Program Files (x86)\HomeSeer HS4\Bin.

                In settings.ini I added
                [Settings]
                ScriptingReferences=ExternalDllTest;bin\ ExternalDllTest.dll
                ​...

                Then I wrote a very simple script in TestScript.cs
                Code:
                //css_reference ExternalDllTest.dll;
                public void Add(object o)
                {
                    ExternalDllTest.TestClass cf = new ExternalDllTest.TestClass();
                    double add = cf.Add(1, 2);
                    //hs.WriteLog("Test", add.ToString());
                }​
                I then added that to an event that I manually trigger:
                Click image for larger version  Name:	TestScript.png Views:	0 Size:	19.4 KB ID:	1666305

                When I run the event, the log file gives me "The type or namespace name `HomeSeerCommonFunctions' could not be found. Are you missing a using directive or an assembly reference?"

                So
                • I have the css_reference in the C# script file.
                • In the script file I use the full name, i.e. including the namespace.
                • I have the relative and absolute path of the dll in settings.ini, which these days should also work with C# scripts (unless it stopped working).
                • The dll is based on .NET 4.0 like the C# scripting execution environment.
                • I don't have a using statement in the script because HS embeds the script into its own class and you can't have a using statement within a class.
                Yet, I still can't get this to work. jon00 tenholde and others, do you have any idea how to get this to work?

                Comment


                  #23
                  Ok, I finally got this to work. I edited the settings.ini file while HS was running. Yesterday I thought maybe HS only reads settings.ini at startup. So I edited the settings.ini file, shut down HS4 and restarted HS4. This was all before posting here.

                  Well, it turns out that with this sequence, HS4 would revert the changes I made to settings.ini file, possibly from the backup file. So I shut down HS4, modified the settings.ini file, deleted the backup file and restarted HS4. Now HS4 kept my changes and the namespace was found. It turns out that I also didn't need the //css_reference and I didn't have to use the full name. Apparently, based on the settings.ini file HS4 puts a using statement in front of the code. So the final script content is this (no css_reference, no using):

                  Code:
                  public void Add(object o)
                  {
                      TestClass cf = new TestClass();
                      double add = cf.Add(1, 2);
                      hs.WriteLog("Test", add.ToString());
                  }​

                  Comment


                    #24
                    Any config files in HS (including plugins) are re-written on shutdown

                    Comment

                    Working...
                    X