我正在将ASP.NET MVC 5应用程序从.NET Framework移植到Mono 最后的前沿是让HostingEnvironment.QueueBackgroundWorkItem工作。
应用程序在Docker容器内的Apache mod_mono上运行。
如标题中所述,HostingEnvironment.QueueBackgroundWorkItem抛出InvalidOperationException。下面是完整的堆栈跟踪。
System.InvalidOperationException: Operation is not valid due to the current state of the object.
at System.Web.Hosting.HostingEnvironment.QueueBackgroundWorkItem (System.Func`2[T,TResult] workItem) [0x00015] in <347f335902b24586a53361aa1278a360>:0
at System.Web.Hosting.HostingEnvironment.QueueBackgroundWorkItem (System.Action`1[T] workItem) [0x00005] in <347f335902b24586a53361aa1278a360>:0
at Ayyeka.Web.UI.Utils.DashboardModelBuilder.SaveModelToCache (Ayyeka.Web.UI.Models.AdminManagementModel model, System.UInt64 userId, System.String token) [0x00005] in <94931e6f7d3d48188e8c013f1bec6e2a>:0
at Ayyeka.Web.UI.Utils.DashboardModelBuilder.build (System.String userUiRole, System.UInt64 userId, System.String token, Ayyeka.Web.UI.BackendUser.User user, System.Boolean cacheModel) [0x004a1] in <94931e6f7d3d48188e8c013f1bec6e2a>:0
我试图跟踪单声道源中的错误,它可能归结为以下方法中的标记行:
public static void QueueBackgroundWorkItem(Func<CancellationToken, Task> workItem) {
if (workItem == null) {
throw new ArgumentNullException("workItem");
}
if (Host == null) { // <------- HERE
throw new InvalidOperationException(); // can only be called within an ASP.NET AppDomain
}
QueueBackgroundWorkItemInternal(workItem);
}
为什么Host为null?我的mod_mono是否配置错误,以至于所有内容都无法在ASP.NET AppDomain中运行?还是不支持?
感谢。