在服务器上加载页面时,Visual Studio 发布的网站出现错误“类型‘JObject’未定义”

问题描述 投票:0回答:1

这适用于 Visual Studio。
它不适用于

Windows 2016 Server Core
运行
IIS 10

发布后没有任何问题。
在服务器上运行网站,我收到错误
Type 'JObject' is not defined.

代码行:
Dim parsejson As JObject = JObject.Parse(json)

所有进口都在那里。

Imports Newtonsoft.Json
Imports Newtonsoft.Json.Linq

Bin
文件夹包含。
Newtonsoft.Json(版本#13.0.3.27908)但没有 .dll 扩展名。
我移动了
Newtonsoft.Json.dll
文件。即使它们大小相同,Windows 也不会认为它们相同,因为
Newtonsoft.Json
被视为
.json
文件。

我认为也许使用

gacutil -i Newtonsoft.Json.dll
注册 .dll 文件可以解决该问题,但它不可注册。
运行时,它将其添加到
cache

但是跑步的时候
gacutil -l Newtonsoft.Json.dll

我明白了
Invalid file or assembly name

所以,它是无法注册的。

我将此添加到

web.config
,但问题仍然相同。
在这里获取此代码表
我假设我正确地执行了旧版本和新版本。由于NewtonSoft dll的版本是
13.0.3.27908

      <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-13.0.3" newVersion="13.0.3" />
          </dependentAssembly>
        </assemblyBinding>
      </runtime> 

我想将其添加为我正在使用的代码。
来自SO
VB.NET 解析 JSON 子节点的代码(底部第二个代码)
我不只使用

[brackets]
{curly brackets}

JSON 示例

{"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!"}}

我正在使用的代码。

 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

我不只使用[括号]而只使用{大括号}。

asp.net vb.net json.net
1个回答
0
投票

我也有同样的问题。
IIS 中,右键单击运行脚本的文件夹。
选择:转换为应用程序
在浏览器中刷新网站,一切都应该可以正常工作。

© www.soinside.com 2019 - 2024. All rights reserved.