谁能告诉我从创建项目时使用的默认版本更新到 Blazor WebAssembly 应用程序中 Bootstrap 和 font Awesome 的较新版本的最佳方法?
我的理解是,当您在对象模型中定义循环引用时,您可以使用此设置来解决出现以下错误的问题:
JsonException: 检测到不支持的可能的对象循环。这可能是由于循环或对象深度大于最大允许深度 32。
但是,我无法成功实施它以使其正常工作。如果有人可以提供有关需要做什么的详细说明,将不胜感激!
我想将应用程序切换为使用 Newtonsoft.JSON,但从我读到的内容来看,这在 Blazor WebAssembly 应用程序中是不可行的?
2020 年 12 月 12 日更新
我在试图弄清楚如何实现 ReferenceHandler.Preserve 时发现的最接近的文章是这些:
https://github.com/dotnet/runtime/issues/42584
https://github.com/dotnet/aspnetcore/issues/28286
基于这些文章,我尝试实施以下解决方案,但都没有奏效......
第一次尝试我在我的 Server 项目的 Startup.cs 类中实现了以下代码:
services.AddControllersWithViews().AddJsonOptions(options =>
{
options.JsonSerializerOptions.ReferenceHandler = System.Text.Json.Serialization.ReferenceHandler.Preserve;
});
Run Code Online (Sandbox Code Playgroud)
第二次尝试我在我的服务器项目的 Startup.cs 类中实现了以下代码:
services.AddControllersWithViews(options =>
{
options.OutputFormatters.RemoveType<SystemTextJsonOutputFormatter>();
options.OutputFormatters.Add(new SystemTextJsonOutputFormatter(new JsonSerializerOptions(JsonSerializerDefaults.Web)
{
ReferenceHandler = ReferenceHandler.Preserve
}));
});
Run Code Online (Sandbox Code Playgroud)
更新 12/12/2020 上午 11:12 CST
在将我的服务器项目更改为面向 .NET 5 并尝试上面的两个代码选项后,我现在在我的应用程序的每个页面上都收到以下类型的错误:
Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] 未处理的异常呈现组件:JSON 值无法转换为 BusinessManager.Shared.Models.EmploymentBenefit[]。路径:$ | 行号:0 | 字节位置内联:1。
重现原始问题的步骤
创建一个新的 Blazor WebAssembly 应用程序
在 Shared 项目中定义一个具有子对象集合的父类,如下所示:
public virtual List<Child> Children{ get; …Run Code Online (Sandbox Code Playgroud) 我有一个非常基本的迁移文件。我dotnet ef database update --verbose在包管理器控制台窗口中执行,但在 SQL Server 中没有生成任何内容。
包管理器控制台窗口中的最后几行输出如下所示:
Finding design-time services for provider Microsoft.EntityFrameworkCore.SqlServer...
Using design-time services from provider Microsoft.EntityFrameworkCore.SqlServer.
Finding design-time services referenced by assembly BM.Server.
No referenced design-time services were found.
Finding IDesignTimeServices implementations in assembly BM.Server...
No design-time services were found.
Done.
Run Code Online (Sandbox Code Playgroud)
这是我的代码的样子,添加和删除迁移工作。它只是试图更新我遇到此问题的数据库。
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
public class Startup
{
public void …Run Code Online (Sandbox Code Playgroud)