[英]Issues with HTML Encoding in ASP.NET Core MVC web application
I just started at a new job as a senior .NET developer, and have run into a very puzzling issue with the package System.Text.Encodings.Web. 我刚开始担任.NET高级开发人员的新工作,但遇到了一个非常令人困惑的问题,即System.Text.Encodings.Web软件包。
The project is in .NET Framework 4.6.1 该项目位于.NET Framework 4.6.1中
The package is showing in the NUGET PACKAGE MANAGER as Installed version 4.5.0, however, the using statement in a .CS file that is trying to use the HtmlEncoder is showing an error with the error text "The type or namespace 'Encodings' does not exist in the namespace 'System.Text'. Are you missing an assembly reference?" 该软件包在NUGET PACKAGE MANAGER中显示为已安装版本4.5.0,但是,尝试使用HtmlEncoder的.CS文件中的using语句显示错误,错误文本为“ The type or namespace'Encodings'名称空间'System.Text'中不存在。是否缺少程序集引用?”
It also says after trying to build, another error, "The type HtmlEncoder is defined in an assembly that is not referenced, You must add a reference to assembly 'System.Text.Encodings.Web, version=4.0.3, Culture=neutral, and then a public key token after that." 它还表示尝试构建后出现另一个错误,“在未引用的程序集中定义了HtmlEncoder类型,您必须添加对程序集'System.Text.Encodings.Web的引用,版本= 4.0.3,Culture = neutral ,然后是一个公共密钥令牌。”
I tried several different things but none of them worked. 我尝试了几种不同的方法,但是没有一种起作用。
In my case, I had the same problem in a NUnitTest project which referenced the main project (both netcorapp2.1). 就我而言,我在引用主项目(均为netcorapp2.1)的NUnitTest项目中遇到了相同的问题。
I have solved the problem by copying the below Package References from the main project into the test project (.csproj files): 我已经通过将以下软件包引用从主项目复制到测试项目(.csproj文件)中来解决了该问题:
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.