Announcement

Collapse
No announcement yet.

Can't get Imports to work in tenScripting3 environment

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

    Can't get Imports to work in tenScripting3 environment

    I have a vb script that uses System.Net.Http. A very simplified version of my script (to exhibit my problem) is as follows:

    Imports System.Net.Http
    Public Sub Main(ByVal param As Object)
    Dim client As HttpClient = New HttpClient()
    End Sub

    This script works fine when run from HomeSeer after I added this line to the [Settings] section of HomeSeer's settings.ini file (thanks to Jon00 for the tip):

    ScriptingReferences=System.Net.Http;System.Net.Http.dll

    Now, I want to continue developing my script with tenScripting3 using Visual Studio Community 2017. I created a simplified version of the script for tenScripting3:

    Imports System.Net.Http ' For: HttpClientPublic Class
    Class MyTest
    Public Sub Main(ByVal param As Object)
    Dim client As HttpClient = New HttpClient()
    End Sub
    End Class

    Unfortunately, Visual Studio 17/tenScripting3 doesn't like my "Imports System.Net.Http". As the below image shows, Visual Studio says that the "Imports System.Net.Http" is unnecessary, and then gives errors that "HttpClient is not defined".

    Is there something I need to change, maybe in my tenscripting3 environment to address this problem? Note that Visual Studio and tenscripting3 are run on a Windows 10 PC that is different than the Windows 10 PC where I run HomeSeer.



    Click image for larger version

Name:	Studio error.png
Views:	182
Size:	209.8 KB
ID:	1377580




    #2
    Just for clarity, it was Sparkman who suggested adding the reference to Settings.ini :-)

    In your project Reference manager, have you selected System.Net & System.Net.Http?

    Click image for larger version  Name:	Capture.PNG Views:	0 Size:	43.6 KB ID:	1377586
    Jon

    Comment


      #3
      Have you thought about using WebClient instead of httpclient? Although httpclient is probably a better choice, at least you would not have the "compatibility" issues you are now experiencing httclient.

      Comment


        #4
        Please review the short video: http://tenholder.net/temp/ImportsProblem.mp4

        tenholde

        Comment


          #5
          Originally posted by aa6vh View Post
          Have you thought about using WebClient instead of httpclient? Although httpclient is probably a better choice, at least you would not have the "compatibility" issues you are now experiencing httclient.
          I used to use WebClient in my script, and it was much simpler. However, as far as I can tell, WebClient doesn't support uploading a file and sending metadata at the same time (i.e. doesn't support multipart/form-data). So, I switched to using HttpClient.

          Comment


            #6
            Oh, yeah, it was sparkman that mentioned the Settings.ini :-)

            So, I tried to do what jon00 and tenholde mentioned. However, in my Reference Manager, I looked under the Framework and Exensions pages, and I couldn't find System.Net.Http. In the Browse page, I only had 4 DLLs (the 4 DLLs including the HomeSeer ones). So, is my PC just missing the DLL for System.Net.Http (if so, how to install)?



            Comment


              #7
              I right-clicked on References->Manage NuGet Packages, searched for System.Net.Http. I selected the latest stable version (4.3.4), and then clicked on Install.
              However, I got the error:

              "Could not install package 'System.Net.Http 4.3.4'. You are trying to install
              ' this package into a project that targets '.NETFramework,Version=v4.0', but the package
              ' does not contain any assembly references or content files that are compatible with
              ' that framework."

              So, using File Explorer, I did a search for System.Net.Http.dll in File Explorer, found one, and copied it to a directory. I did References->Add Reference->Browse to add System.Net.Http.dll. Now, my script is past this problem. I'm now getting error related to "Await" in my "Await httpClient.PostAsync()" call, which works fine when run in HS3 but not in Visual Studio. But, that's another problem and the initial issue I had posted is now resolved. Thanks, folks!

              Comment

              Working...
              X