I am in the midst of porting an ASP.NET MVC 5 application from .NET Framework to Mono.
The final frontier is getting HostingEnvironment.QueueBackgroundWorkItem to work.
The application runs on Apache mod_mono, within a docker container.
As said in title, HostingEnvironment.QueueBackgroundWorkItem throws InvalidOperationException. Below is the full stack trace.
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
I've tried to trace the error in the mono source and it's probably boils down to the marked line in the following method:
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);
}
Why is Host null? Is my mod_mono mis-configured so that everything doesn't run within ASP.NET AppDomain? Or is it not supported?
Thanks.