Announcement

Collapse
No announcement yet.

Referencing a vb.net dll or exe from a script?

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

    Referencing a vb.net dll or exe from a script?

    Has anyone had any luck referencing a vb.net class library (.dll) from a script (.vb) in HomeSeer? It would be helpful to be able to call routines located in an external vb.net dll or perhaps an exe. I have tried to read up on this but I still don't know if it can be done or not. My attempts so far have been unsuccessful.

    I know there is a lot of talent here, and I hope some of you will chime in on this, hopefully with some details.

    Thanks!
    Brian

    #2
    Unfortunately, references to external dlls is a global setting. It can't be set for each script unless you are using the Script Connector plugin.

    The global parameter is in config/settings.ini, section [Settings], parameter
    ScriptingReferences=...

    If you are using the Script Connector plugin, you can add one or several #USING directives at the top of each script. This allows different set of references for each script.
    --
    stipus

    Comment


      #3
      Originally posted by stipus View Post
      Unfortunately, references to external dlls is a global setting. It can't be set for each script unless you are using the Script Connector plugin.

      The global parameter is in config/settings.ini, section [Settings], parameter
      ScriptingReferences=...

      If you are using the Script Connector plugin, you can add one or several #USING directives at the top of each script. This allows different set of references for each script.

      Thanks for the reply.

      Would setting a global parameter in the ScriptingReferences not allow access to that dll, from any of HomeSeer's (.vb) scripts? I am trying to understand what the capabilities and limitations are.

      If this will not work would the script connector plugin solve this problem? Would their be other advantages to using the product?

      My use of HS at this point only involves the local machine, I am not accessing the HS program from other locations.

      Thanks!
      Brian

      Comment


        #4
        Just add your DLL and DLL path to the ScriptingReferences= parameter, and you can then call the assembly from any .VB script.

        This setting is global to all .VB scripts executed by HomeSeer.
        --
        stipus

        Comment


          #5
          Originally posted by stipus View Post
          Unfortunately, references to external dlls is a global setting. It can't be set for each script unless you are using the Script Connector plugin.
          Wait a minute.... I thought that was what the IMPORTS statement did. In fact, isn't that what this portion of the help file is about: http://homeseer.com/support/homeseer...namespaces.htm

          Steve

          Comment


            #6
            Originally posted by stipus View Post
            Just add your DLL and DLL path to the ScriptingReferences= parameter, and you can then call the assembly from any .VB script.

            This setting is global to all .VB scripts executed by HomeSeer.
            Stipus,

            I have tried adding my vb.net class library (.dll) to the ScriptingReferences= parameter. I can get HomeSeer to start without an error but when I try to call it from a script I get an error in the HomeSeer log.

            TestApp is a vb.net dll with one Public Class JRMC. I can reference it in another vb.net app and call it with no problems.

            This is my entry in the settings.ini file:
            ScriptingReferences = System.xml;System.xml.dll,TestApp.JRMC;C:\DotNet2005\TestApp \TestApp\bin\Debug\TestApp.dll

            If I run the following script I get the error below:

            Sub Main(ByVal parm As Object)

            Dim J as New TestApp.JRMC

            End Sub

            3/17/2008 9:08:47 AM - Error - Scripting runtime error: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileNotFoundException: Could not load file or assembly 'TestApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.File name: 'TestApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' at scriptcode4.scriptcode4.Main(Object parm)WRN: Assembly binding logging is turned OFF.To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.Note: There is some performance penalty associated with assembly bind failure logging.To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog]. --- End of inner exception stack trace --- at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) at Scheduler.VsaScriptHost.Invoke(String ModuleName, String MethodName, Object[] Arguments)

            If I run the following script I get the error below:

            IMPORTS TestApp.JRMC
            Sub Main(ByVal parm As Object)

            Dim J as New TestApp.JRMC

            End Sub

            3/17/2008 9:38:36 AM - Error - Script compile error: 'Imports' statements must precede any declarations.on line 14


            I am sorry this is so long. Can you tell what I am doing wrong?

            Thanks again!
            Brian
            Last edited by bdhall; March 17, 2008, 09:41 AM.

            Comment


              #7
              Brian,
              Look at the help page link I posted above. I think using the IMPORTS statement will take care of you problem.
              Steve

              Comment


                #8
                There is a subtle difference between Referencing a DLL, and the IMPORT keyword.

                Referencing a DLL is mandatory if you want to use it. This means you always need to add your DLL to the ScriptingReferences parameter. Period.

                Then the IMPORT keyword creates a shortcut to the namespace, so that you don't have to type the complete path of the objects in your code. This is optional.
                --
                stipus

                Comment


                  #9
                  Originally posted by stevea View Post
                  Brian,
                  Look at the help page link I posted above. I think using the IMPORTS statement will take care of you problem.
                  Steve
                  Steve,

                  I have looked at this one quite a bit. I did discover that I did not have the "IMPORTS" statement in uppercase. When I changed that in the script my error changed. I noted the new error in my previous post. (the long one)

                  Thanks again!
                  Brian

                  Comment


                    #10
                    Originally posted by stipus View Post
                    There is a subtle difference between Referencing a DLL, and the IMPORT keyword.

                    Referencing a DLL is mandatory if you want to use it. This means you always need to add your DLL to the ScriptingReferences parameter. Period.

                    Then the IMPORT keyword creates a shortcut to the namespace, so that you don't have to type the complete path of the objects in your code. This is optional.
                    Stipus,

                    I did find that I did not have the "IMPORTS" statement in upper case, when I made that change I got a different error. I edited my previous post to reflect the change.

                    Does my "ScriptingReferences" and my HS (.vb) script look correct? Notice the "System.IO.FileNotFoundException" in error message contained in the log entry.

                    Any thoughts on what I might be doing wrong here?

                    I seem to have a lot more trouble dealing with the HS scripting than with straight vb.net.

                    Do you know of a simple example anywhere that I might could look at?

                    Thanks!
                    Brian

                    Comment


                      #11
                      Here is one of the sample SIP Connector scripts:

                      Code:
                      [FONT=Courier New][COLOR=#0000bb]Imports HSPI_SIP [/COLOR][/FONT]
                      [FONT=Courier New][COLOR=#0000bb]
                      Sub Init[/COLOR][COLOR=#007700]( [/COLOR][COLOR=#0000bb]ByVal c [/COLOR][COLOR=#007700]as [/COLOR][COLOR=#0000bb]SipCall [/COLOR][/FONT][FONT=Courier New][COLOR=#007700])
                      [/COLOR][COLOR=#0000bb]SpeakWeather[/COLOR][COLOR=#007700]( [/COLOR][COLOR=#0000bb]c [/COLOR][/FONT][FONT=Courier New][COLOR=#007700])
                      [/COLOR][/FONT][FONT=Courier New][COLOR=#0000bb]End Sub
                      
                      Sub CallConnected[/COLOR][COLOR=#007700]( [/COLOR][COLOR=#0000bb]ByVal c [/COLOR][COLOR=#007700]as [/COLOR][COLOR=#0000bb]SipCall [/COLOR][/FONT][FONT=Courier New][COLOR=#007700])
                      [/COLOR][COLOR=#0000bb]SpeakWeather[/COLOR][COLOR=#007700]( [/COLOR][COLOR=#0000bb]c [/COLOR][/FONT][FONT=Courier New][COLOR=#007700])
                      [/COLOR][/FONT][FONT=Courier New][COLOR=#0000bb]End Sub
                      
                      Sub SpeakWeather[/COLOR][COLOR=#007700]( [/COLOR][COLOR=#0000bb]ByVal c [/COLOR][COLOR=#007700]as [/COLOR][COLOR=#0000bb]SipCall [/COLOR][/FONT][FONT=Courier New][COLOR=#007700])
                          [/COLOR][COLOR=#0000bb]Dim outdoorTemp [/COLOR][COLOR=#007700]As [/COLOR][COLOR=#0000bb]String [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]hs[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]DeviceString[/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]"A1"[/COLOR][/FONT][FONT=Courier New][COLOR=#007700])
                          [/COLOR][COLOR=#0000bb]Dim outdoorHumidity [/COLOR][COLOR=#007700]As [/COLOR][COLOR=#0000bb]String [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]hs[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]DeviceString[/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]"A1"[/COLOR][/FONT][FONT=Courier New][COLOR=#007700])
                          [/COLOR][COLOR=#0000bb]Dim gustWindSpeed [/COLOR][COLOR=#007700]As [/COLOR][COLOR=#0000bb]String [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]hs[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]DeviceString[/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]"A1"[/COLOR][/FONT][FONT=Courier New][COLOR=#007700])
                          [/COLOR][COLOR=#0000bb]Dim windDirection [/COLOR][COLOR=#007700]As [/COLOR][COLOR=#0000bb]String [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]hs[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]DeviceString[/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]"A1"[/COLOR][/FONT][FONT=Courier New][COLOR=#007700])
                          [/COLOR][COLOR=#0000bb]Dim feltTemp [/COLOR][COLOR=#007700]As [/COLOR][COLOR=#0000bb]String [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]hs[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]DeviceString[/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]"A1"[/COLOR][/FONT][FONT=Courier New][COLOR=#007700])
                          [/COLOR][COLOR=#0000bb]Dim dewPoint [/COLOR][COLOR=#007700]As [/COLOR][COLOR=#0000bb]String [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]hs[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]DeviceString[/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]"A1"[/COLOR][/FONT][FONT=Courier New][COLOR=#007700])
                          [/COLOR][COLOR=#0000bb]Dim skies [/COLOR][COLOR=#007700]As [/COLOR][COLOR=#0000bb]String [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]hs[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]DeviceString[/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]"A1"[/COLOR][/FONT][FONT=Courier New][COLOR=#007700])
                          [/COLOR][COLOR=#0000bb]Dim weather [/COLOR][COLOR=#007700]as [/COLOR][COLOR=#0000bb]String [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#dd0000]"The temperature outside is " [/COLOR][COLOR=#007700]& [/COLOR][COLOR=#0000bb]outdoorTemp [/COLOR][COLOR=#007700]& [/COLOR][COLOR=#dd0000]" degrees ,with a Humidity of " [/COLOR][COLOR=#007700]& [/COLOR][COLOR=#0000bb]outdoorHumidity [/COLOR][COLOR=#007700]& [/COLOR][COLOR=#dd0000]". The wind is currently gusting to " [/COLOR][COLOR=#007700]& [/COLOR][COLOR=#0000bb]gustWindSpeed [/COLOR][COLOR=#007700]& [/COLOR][COLOR=#dd0000]" Miles per hour from a wind direction of " [/COLOR][COLOR=#007700]& [/COLOR][COLOR=#0000bb]windDirection [/COLOR][COLOR=#007700]& [/COLOR][COLOR=#dd0000]" degrees. The current heat index makes it feel like " [/COLOR][COLOR=#007700]& [/COLOR][COLOR=#0000bb]feltTemp [/COLOR][COLOR=#007700]& [/COLOR][COLOR=#dd0000]" degrees, and the dewpoint is " [/COLOR][COLOR=#007700]& [/COLOR][COLOR=#0000bb]dewPoint [/COLOR][COLOR=#007700]& [/COLOR][COLOR=#dd0000]" degrees. The skies are " [/COLOR][COLOR=#007700]& [/COLOR][/FONT][FONT=Courier New][COLOR=#0000bb]skies
                          c[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]SpeakTextWait[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]weather[/COLOR][/FONT][FONT=Courier New][COLOR=#007700])
                          [/COLOR][COLOR=#0000bb]c[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]Hangup[/COLOR][/FONT][FONT=Courier New][COLOR=#007700]()
                      [/COLOR][/FONT][FONT=Courier New][COLOR=#0000bb]End Sub
                      
                      Sub CallHungup[/COLOR][COLOR=#007700]( [/COLOR][COLOR=#0000bb]ByVal c [/COLOR][COLOR=#007700]as [/COLOR][COLOR=#0000bb]SipCall [/COLOR][/FONT][FONT=Courier New][COLOR=#007700])
                      [/COLOR][/FONT][COLOR=#0000bb][FONT=Courier New]End Sub [/FONT]
                      [/COLOR]


                      Notice that the Imports statement must be followed by the name of the namespace (that is not necessary the same as the assembly name).
                      <!-- php buffer end -->
                      --
                      stipus

                      Comment


                        #12
                        Originally posted by brian270999 View Post
                        Stipus,

                        I have tried adding my vb.net class library (.dll) to the ScriptingReferences= parameter. I can get HomeSeer to start without an error but when I try to call it from a script I get an error in the HomeSeer log.

                        TestApp is a vb.net dll with one Public Class JRMC. I can reference it in another vb.net app and call it with no problems.

                        This is my entry in the settings.ini file:
                        ScriptingReferences = System.xml;System.xml.dll,TestApp.JRMC;C:\DotNet2005\TestApp \TestApp\bin\Debug\TestApp.dll

                        If I run the following script I get the error below:

                        Sub Main(ByVal parm As Object)

                        Dim J as New TestApp.JRMC

                        End Sub

                        3/17/2008 9:08:47 AM - Error - Scripting runtime error: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileNotFoundException: Could not load file or assembly 'TestApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.File name: 'TestApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' at scriptcode4.scriptcode4.Main(Object parm)WRN: Assembly binding logging is turned OFF.To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.Note: There is some performance penalty associated with assembly bind failure logging.To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog]. --- End of inner exception stack trace --- at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) at Scheduler.VsaScriptHost.Invoke(String ModuleName, String MethodName, Object[] Arguments)

                        Brian, I can confirm your results. I get the same file not found exception when referencing my custom assemly from a script.

                        However, it doesn't fail when referencing my assembly from an aspx page. In that case it works as it should.

                        Regards,
                        Reg

                        Comment


                          #13
                          Have you tried placing your DLL in the Homeseer root and then referencing them without a path?
                          Jon

                          Comment


                            #14
                            Originally posted by brian270999 View Post
                            Does my "ScriptingReferences" and my HS (.vb) script look correct?
                            Actually, it doesn't look right to me. According to the help file, each entry should be a pair: First the name space, a semicolon, then the DLL name. Each pair is separated by a comma. What you show doesn't match that at all. I'm guessing that you mean to have the following:
                            Code:
                            ScriptingReferences = System.xml;System.xml.dll,TestApp;C:\TestApp\bin\Debug\TestApp.dll
                            Or am I missing something else?

                            Steve
                            Last edited by stevea; March 17, 2008, 01:18 PM. Reason: typo

                            Comment


                              #15
                              Originally posted by jon00 View Post
                              Have you tried placing your DLL in the Homeseer root and then referencing them without a path?
                              I would also try this.
                              --
                              stipus

                              Comment

                              Working...
                              X