.net - .Net core 3.1 发布后未找到 Antiforgery.dll
问题描述
我有一个使用 .Net core 3.1 构建的带有 ContactUs 表单的简单应用程序。我正在使用 Razor light 包来渲染剃须刀模板并使用 Fluent 电子邮件 api。
在开发过程中,一切正常。但是,当我发布应用程序时,我在尝试发送电子邮件时收到以下错误
System.InvalidOperationException: Cannot find reference assembly 'Microsoft.AspNetCore.Antiforgery.dll' file for package Microsoft.AspNetCore.Antiforgery.Reference
at BondhEShams.Web.Controllers.HomeController.ContactUs(Contact model) in E:\Work\AbdulMalikYoosufani\BondhEShams\BondhEShams\BondhEShams.Web\Controllers\HomeController.cs:line 85
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)
如何解决这个问题?我什至在我的项目文件中添加以下行
<PreserveCompilationReferences>true</PreserveCompilationReferences>
<PreserveCompilationContext>true</PreserveCompilationContext>
但这也没有成功。该错误仅在发布后发生。我还注意到发布目录中没有 Antiforgery.dll
解决方案
推荐阅读
- python - 磁力计的校准没有给出预期的结果
- haskell - 如何在 Haskell 中实现`assertFail`?
- chisel - 你如何两次实例化同一个模块?
- python - 如何在 python 中使用 fileinput.input 获取每一行的值
- apache-spark - 如何修复“ImportError:PyArrow >= 0.8.0 必须安装;但是,它没有找到。”?
- java - 如何计算两个数组列表上匹配值的百分比?
- r - 在 R 闪亮返回参数对象中使用 highchart 绘制两列缺少没有值
- identityserver4 - 使用 HS256 签署 Identity Server 4 令牌
- arrays - 如何在 Match 函数中连接多个范围
- powershell - 脚本不提示用户输入