Results 1 to 2 of 2

Thread: website gets error "Type 'JObject' is not defined" (Newtonsoft.json)

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2017
    Posts
    29

    website gets error "Type 'JObject' is not defined" (Newtonsoft.json)

    This works in Visual Studio.
    It does not work on `Windows 2016 Server Core` running `IIS 10`.
    When published, there are no issues.
    Run the website on the server, I receive the error `Type 'JObject' is not defined.`.
    Code line: `Dim parsejson As JObject = JObject.Parse(json)`

    All imports are there.

    Code:
        Imports Newtonsoft.Json
        Imports Newtonsoft.Json.Linq

    The `Bin` folder contains.
    Newtonsoft.Json.dll (Version # 13.0.3.27908)

    I thought maybe registering the .dll file with `gacutil -i Newtonsoft.Json.dll` would resolve the issue, but it is not registerable.
    When run, it adds it to the `cache`.
    But when running `gacutil -l Newtonsoft.Json.dll`
    I get `Invalid file or assembly name`
    So, it is unregisterable.

    I added this to the `web.config`, but the issue is still the same.

    Code:
              <runtime>
                <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
                  <dependentAssembly>
                    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="13.0.3.27908" />
                  </dependentAssembly>
                </assemblyBinding>
              </runtime>
    I wanted to add this as the code I am using.
    VB.NET Code To Parse Child Node Of JSON (Second code at the bottom)
    I am not using [brackets] only {curly brackets}.

    An example of the JSON can be found at the link above. (Broken into lines to fit code view better)
    To view the actual JSON
    Code:
        {"data":
        {"id":3,"name":"true red","year":2002,"color":"#BF1932","pantone_value":"19-1664"}
        ,"support":
        {"url":"https://reqres.in/#support-heading","text":
        "To keep ReqRes free, contributions towards server costs are appreciated!"}}
    The code I am using.
    Code:
         Imports System.Net
            Imports Newtonsoft.Json.Linq
            
            Public Class Form1
                Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
                    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
                    Dim json As String = New System.Net.WebClient().DownloadString("https://reqres.in/api/products/3")
                    Dim parsejson As JObject = JObject.Parse(json)
                    Dim thename = parsejson.SelectToken("data.name").ToString()
                    txt1.Text = "Name Is " + thename
                End Sub
            End Class

  2. #2

    Thread Starter
    Junior Member
    Join Date
    Feb 2017
    Posts
    29

    Re: website gets error "Type 'JObject' is not defined" (Newtonsoft.json)

    I had to remember what I had done years ago.
    In IIS, Right-click on the folder from which the script is running.
    Choose: Convert to Application.
    Refresh the website in your browser, and everything went to working.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width