.net core 在.NETCore3.1中读取RSS不起作用
我有一个非常简单的.NET Core Web Api代码,它以前在.NET Core 2.2中工作,但升级到3.1后停止工作.net core 在.NETCore3.1中读取RSS不起作用,.net-core,rss,syndication-feed,.net Core,Rss,Syndication Feed,我有一个非常简单的.NET Core Web Api代码,它以前在.NET Core 2.2中工作,但升级到3.1后停止工作 [HttpGet] [Route("api/news")] public IEnumerable<SyndicationItem> GetNews(string source) { var feed = SyndicationFeed.Load(XmlReader.Create(source)); return feed.Items; } 我
[HttpGet]
[Route("api/news")]
public IEnumerable<SyndicationItem> GetNews(string source)
{
var feed = SyndicationFeed.Load(XmlReader.Create(source));
return feed.Items;
}
我可以通过导航到以下位置来调用它:
在debug中,我可以看到它可以很好地获取项目,但返回这些项目时会抛出此错误,我不明白为什么它在升级到3.1后停止工作,以及如何修复它
请大家多多指教,谢谢
System.NotSupportedException:不支持“System.ServiceModel.Syndication.SyndicationItem.AttributeExtensions”上的集合类型“System.Collections.Generic.Dictionary”2[System.Xml.XmlQualifiedName,System.String]”。
在System.Text.Json.JsonClassInfo.GetElementTypeType属性类型、类型parentType、MemberInfo MemberInfo、JsonSerializerOptions选项中
在System.Text.Json.JsonClassInfo.CreatePropertyType declaredPropertyType、Type runtimePropertyType、Type implementedPropertyType、PropertyInfo PropertyInfo、Type parentClassType、JsonConverter转换器、JsonSerializerOptions选项中
在System.Text.Json.JsonClassInfo.AddPropertyType propertyType、PropertyInfo PropertyInfo、Type classType、JsonSerializerOptions选项中
在System.Text.Json.JsonClassInfo..ctorType类型中,选择JsonSerializerOptions选项
位于System.Text.Json.JsonSerializerOptions.GetOradClassType
位于System.Text.Json.JsonClassInfo.get_ElementClassInfo
位于System.Text.Json.JsonSerializer.WriteUtf8JsonWriter writer、Int32 originalWriterDepth、Int32 flushtreshold、jsonserializedroptions选项、WriteStack和state
位于System.Text.Json.JsonSerializer.WriteAsyncCrestream utf8Json,对象值,输入类型,JsonSerializerOptions选项,CancellationToken CancellationToken
在Microsoft.AspNetCore.Mvc.Formatters.SystemTextJsonOutputFormatter.WriteResponseBodyAsyncoutFormatter WriteContext中,编码选择编码
在Microsoft.AspNetCore.Mvc.Formatters.SystemTextJsonOutputFormatter.WriteResponseBodyAsyncoutFormatter WriteContext中,编码选择编码
在Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g_|29_0[TFilter,TFilterAsync]ResourceInvoker invoker,Task lastTask,State next,Scope Scope,Object State,Boolean isCompleted
在Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.RethrowResultExecutedContextSealed上下文中
在Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync]状态和下一步,作用域和作用域,对象和状态,布尔值和已完成
位于Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters
-来自引发异常的上一个位置的堆栈结束跟踪--
在Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g|u等待| 24_0ResourceInvoker invoker、Task lastTask、State next、Scope Scope、Object State、Boolean isCompleted
在Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.RethrowResourceExecutedContextSealed上下文中
在Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.NextState&next、Scope&Scope、Object&state、Boolean&isCompleted中
位于Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync
-来自引发异常的上一个位置的堆栈结束跟踪--
在Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g|u等待| 17|u 0ResourceInvoker invoker,Task Task,IDisposable作用域
在Microsoft.AspNetCore.Routing.EndpointMiddleware.g_uwaitRequestTask | 6_0端点,Task requestTask,ILogger logger
在Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.InvokeHttpContext上下文中
.NET Core 3.x中的默认JSON序列化程序更改为System.Text.JSON。在这种情况下,您可能需要指定使用Newtonsoft.Json作为默认序列化程序.NETCore旧版本中的默认序列化程序
在Startup.cs中:
公共无效配置服务服务服务收集服务
{
services.AddControllers.AddNewtonsoftJson;
//ConfigureServices中的其他设置。。。
}
错误表明System.Text.Json API存在问题,该API内置于ASP.NET Core 3.x中。试着切换回Newtonsoft.Json库我从来没有明确使用过System.Text.Json或Newtonsoft.Json,这两行代码就是我的全部,我无法切换回去,因为我从未向前切换过:System.Text.Json是ASP.NET Core 3.x中的默认Json序列化程序。这篇文章告诉您更多我知道它是什么:我说过我从未在代码中显式使用它。你在我的帖子里看到这两行代码了吗?就是这样。