dotnetcore / WebApiClient

A REST API library with better functionality, performance, and scalability than refit
https://webapiclient.github.io/
MIT License
2.03k stars 445 forks source link

.net release 编译发布后,原来接口返回ITask包装的都会抛出异常 #198

Closed nankingcigar closed 2 years ago

nankingcigar commented 2 years ago

.net release 编译发布后,原来接口返回ITask包装的都会抛出异常,只要一await就会抛出这个异常 2022-01-06 06:15:05.118 +00:00 [ERR] Object reference not set to an instance of an object. System.NullReferenceException: Object reference not set to an instance of an object. at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.get_IsCompleted() at AlterDomus.ClientDashboard.Application.Service.FundService.GetUserPermissionedFunds(Int32 mcpUserId, String permission, CancellationToken cancellationToken) in D:\work\project\ADWS\code\master\CorPro\AlterDomus.ClientDashboard\src\AlterDomus.ClientDashboard.Application\Service\FundService.cs:line 88

nankingcigar commented 2 years ago

.net 6.0 环境 release下发布 有这个情况,debug情况下都是好的

nankingcigar commented 2 years ago

经排查,是使用了continueawait.fody,配置了全局,该配置只在release模式下工作,continueawait.fody会静态编译优化异步操作,相当于默认加上Task.ConfigureAwait(false),减少上下文的创建

nankingcigar commented 2 years ago

.net 5/6只要使用了该库release下优化代码编译,都会导致异常

nankingcigar commented 2 years ago

是否能考虑下ITask兼容continueawait.fody 这类静态提升或者优化异步性能库的?