【问题标题】:.NET Core 5 RawRabbit Serializer/Dependency Injection Issue.NET Core 5 RawRabbit 序列化器/依赖注入问题
【发布时间】:2022-01-02 13:28:39
【问题描述】:

我有基于 .NET Core 2.2 的微服务。我使用 RawRabbit(版本 2.0.0-beta9)作为服务总线。与它一起安装了以下软件包:

<PackageReference Include="RawRabbit" Version="2.0.0-beta9" />
<PackageReference Include="RawRabbit.DependencyInjection.ServiceCollection" Version="2.0.0-beta9" />
<PackageReference Include="RawRabbit.Operations.Publish" Version="2.0.0-beta9" />
<PackageReference Include="RawRabbit.Operations.Subscribe" Version="2.0.0-beta9" />

这是我的控制器的样子:

 private readonly IBusClient _busClient;

//...constructor that inits the _busClient

[HttpPost("")]
public async Task<IActionResult> Post([FromBody] CreateActivity model)
{
    model.Id = Guid.NewGuid();
    await _busClient.PublishAsync(model); //Exception thrown here
    return Accepted($"Activities/{model.Name}");
}

当代码尝试执行以下操作时会出现问题:

await _busClient.PublishAsync(model);

我得到的例外是:

找不到方法:'Void Newtonsoft.Json.JsonSerializer.set_TypeNameAssemblyFormat(System.Runtime.Serialization.Formatters.FormatterAssemblyStyle)'。

【问题讨论】:

  • 我很困惑,你的标题说你有一个 .NET Core 5 项目,但描述说的是 .NET Core 2.2!

标签: c# asp.net-core .net-core microservices csharpcodeprovider


【解决方案1】:

似乎它与您的消息代理或发布无关(顺便说一下,如果您提到消息是否被您的消费者收到可能会更好) 但似乎你在牛顿 JSON 中使用 TypeNameAssemblyFormat 的地方,根据here,它现在已经过时了。

[ObsoleteAttribute("TypeNameAssemblyFormat is obsolete. Use TypeNameAssemblyFormatHandling instead.")]
public FormatterAssemblyStyle TypeNameAssemblyFormat { get; set; }

您应该使用 TypeNameAssemblyFormatHandling。 另见here

【讨论】:

    猜你喜欢
    • 2019-09-14
    • 2018-04-05
    • 2016-05-22
    • 1970-01-01
    • 1970-01-01
    • 2021-10-23
    • 1970-01-01
    • 2021-02-02
    • 1970-01-01
    相关资源
    最近更新 更多