小编Col*_*ett的帖子

Json.NET Uri(反序列化)错误

我需要使用最新的(4.0.3)Json.NET库对包含System.Uri属性的对象进行序列化和反序列化。

以下代码演示了该问题:

string input = "http://test.com/%22foo+bar%22";
Uri uri = new Uri(input);
string json = JsonConvert.SerializeObject(uri);
Uri output = JsonConvert.DeserializeObject<Uri>(json);
Run Code Online (Sandbox Code Playgroud)

DeserializeObject方法抛出JsonReaderException。在4.0.2。下可以正常工作。

我已经通过测试和修补程序在Codeplex上提交了一个问题,以解决该问题,但是作者发布固定版本似乎需要一点时间。

同时,我能做些什么(使用JsonSettings或其他方法)来使最新版本按预期工作吗?

到目前为止,我有几个选择:

  1. 坚持4.0.2-新的nuget包取决于4.0.3
  2. 将uri更改为字符串-我宁愿选择选项1和手动管理的pkg依赖项
  3. 使用应用了补丁的自定义版本-这是我现在正在做的事情,但是我讨厌覆盖nuget包的程序集的想法。

c# serialization json.net deserialization

3
推荐指数
1
解决办法
3921
查看次数

检查 DbSet&lt;T&gt; 是否为空

我正在研究一种从 json 为 EF Core 数据库做种的方法。因此,我有一系列方法可以像下面那样为每个实体(FilterList并且Language是两个示例实体)发挥作用。除了名称、dbset 属性名称和实体类型的两个实例之外,这些方法都是相同的。

private static void SeedFilterLists(FilterListsDbContext context)
{
    if (context.FilterLists.Any()) return;
    var types = JsonConvert.DeserializeObject<List<FilterList>>(
        File.ReadAllText(SeedDirectory + Path.DirectorySeparatorChar + typeof(FilterList).Name + ".json"));
    context.AddRange(types);
    context.SaveChanges();
}

private static void SeedLanguages(FilterListsDbContext context)
{
    if (context.Languages.Any()) return;
    var types = JsonConvert.DeserializeObject<List<Language>>(
        File.ReadAllText(SeedDirectory + Path.DirectorySeparatorChar + typeof(Language).Name + ".json"));
    context.AddRange(types);
    context.SaveChanges();
}
Run Code Online (Sandbox Code Playgroud)

我想用一个通用方法替换所有这些重复。我已经尝试过类似下面的东西,但它并不完全存在。我不确定如何引用 DbSet 属性。我可以用什么来代替注释行中的问号,或者有没有更好的替代方法来查看泛型类型的表是否为空?

//TODO: fix generic method to remove duplication of entity-specific methods
private static void Seed<T>(DbContext context)
{
    //if (context.?.Any()) return;
    var …
Run Code Online (Sandbox Code Playgroud)

.net c# generics entity-framework entity-framework-core

3
推荐指数
1
解决办法
2387
查看次数

引用不存在的lib目录中的依赖项的“ dotnet publish”错误

我正在尝试通过Travis CI将dotnet核心Web应用程序部署到Ubuntu VPS。我正在dotnet restore && dotnet publish -c release -r ubuntu.16.04-x64构建,然后才扩展到服务器。在Travis上构建和部署可以很好地完成,但是当我在服务器上重新启动应用程序服务时,会出现诸如以下错误。

Error: assembly specified in the dependencies manifest was not found -- package: 'microsoft.aspnetcore.antiforgery', version: '1.1.1', path: 'lib/netstandard1.3/Microsoft.AspNetCore.Antiforgery.dll'

*.deps.json作为发布的一部分而创建的文件具有以下几行。

"microsoft.aspnetcore.antiforgery/1.1.1": {
    "dependencies": {
      "Microsoft.AspNetCore.DataProtection": "1.1.1",
      "Microsoft.AspNetCore.Http.Abstractions": "1.1.1",
      "Microsoft.AspNetCore.Http.Extensions": "1.1.1",
      "Microsoft.AspNetCore.WebUtilities": "1.1.1",
      "Microsoft.Extensions.ObjectPool": "1.1.0",
      "NETStandard.Library": "1.6.1"
    },
    "compile": {
      "lib/netstandard1.3/Microsoft.AspNetCore.Antiforgery.dll": {}
    }
  },
  "microsoft.aspnetcore.authorization/1.1.1": {
    "dependencies": {
      "Microsoft.Extensions.Logging.Abstractions": "1.1.1",
      "Microsoft.Extensions.Options": "1.1.1",
      "NETStandard.Library": "1.6.1",
      "System.Security.Claims": "4.3.0"
    },
    "compile": {
      "lib/netstandard1.3/Microsoft.AspNetCore.Authorization.dll": {}
    }
},
Run Code Online (Sandbox Code Playgroud)

这些“ compile”属性是导致此问题的原因,因为如果我手动删除的compile属性lib/netstandard1.3/Microsoft.AspNetCore.Antiforgery.dll,则错误现在变为:

Error: assembly …

dll nuget travis-ci asp.net-core .net-standard

1
推荐指数
1
解决办法
1213
查看次数

嵌套的自定义FormArray组件不与具有FormArrayName的子窗体绑定

我试图使用CVA具有2个嵌套表单。问题是当我将第二个from绑定到formControl时没有用数据初始化。

Stackblitz

在此处输入图片说明

我有主表格

this.requestForm = this.fb.group({
  garageId: 0,
  routes: new FormArray([
    new FormGroup({
      addressPointId: new FormControl,
      municipalityId: new FormControl,
      regionId: new FormControl,
      rvId: new FormControl,
      sequenceNumber: new FormControl,
      settlementId: new FormControl,
      regionName: new FormControl,
      municipalityName: new FormControl,
      settlementName: new FormControl,
      description: new FormControl,
    })
  ]),
  endDateTime: 0,
});
Run Code Online (Sandbox Code Playgroud)

在主要形式的html中,我使用formArrayName将路由绑定到。

 <app-cva-form-array formArrayName="routes"></app-cva-form-array>
Run Code Online (Sandbox Code Playgroud)

组件CVA-FORM-ARRAY具有。

form = new FormArray([
new FormGroup({
  addressPointId: new FormControl,
  municipalityId: new FormControl,
  regionId: new FormControl,
  rvId: new FormControl,
  sequenceNumber: new FormControl,
  settlementId: new FormControl, …
Run Code Online (Sandbox Code Playgroud)

typescript angular angular-reactive-forms controlvalueaccessor

0
推荐指数
1
解决办法
1168
查看次数