Skip to content

Commit 6adcc6b

Browse files
committed
Throw if ModuleActions is accessed to early.
+ some code comments.
1 parent cee5c2a commit 6adcc6b

4 files changed

Lines changed: 5 additions & 5 deletions

File tree

DNN Platform/DotNetNuke.Web.Mvc/AsyncMvcHostControl.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ protected override void OnInitInternal(EventArgs e)
3636

3737
protected override void OnPreRenderInternal(EventArgs e)
3838
{
39+
// We need to defer execution to after the async task registered in OnInitInternal above, which will only get executed at the WebForms async point, just before PreRenderComplete.
3940
this.Page.RegisterAsyncTask(new PageAsyncTask(this.OnPreRenderAsync));
4041
}
4142

DNN Platform/Library/UI/Containers/ActionBase.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ protected void ProcessAction(string actionID)
113113
{
114114
if (this.ModuleControl is IAsyncModuleControl)
115115
{
116+
// We need to defer accesing this.Actions as it could only be accesible after the WebForms async point.
116117
this.Page.RegisterAsyncTask(new PageAsyncTask(ct => this.ProcessActionInternalAsync(actionID, ct)));
117118
}
118119
else

DNN Platform/Library/UI/Modules/ModuleInstanceContext.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -511,13 +511,10 @@ private void LoadActions(HttpRequest request)
511511
if (actionable != null)
512512
{
513513
// Async module controls populate ModuleActions only after their async task executes.
514-
// Leave this.actions as null so the Actions getter retries once results are available.
515514
if (this.moduleControl is IAsyncModuleControl && actionable.ModuleActions == null)
516515
{
517-
this.actions = null;
518-
519-
// TODO: Should we throw instead to be able to identify code that tries to call it too early?
520-
return;
516+
throw new InvalidOperationException("Too early to access the ModuleActions. For async controls, ModuleActions collection is available only after the framework executes the `Page.ExecuteRegisteredAsyncTasks()`. " +
517+
"More specifically, you have to either register an async task using `Page.RegisterAsyncTask()` or use any of the sync events starting from PreRenderComplete to access them.");
521518
}
522519

523520
this.moduleSpecificActions = new ModuleAction(this.GetNextActionID(), Localization.GetString("ModuleSpecificActions.Action", Localization.GlobalResourceFile), string.Empty, string.Empty, string.Empty);

DNN Platform/Website/admin/Menus/ModuleActions/ModuleActions.ascx.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ protected override void OnLoad(EventArgs e)
158158

159159
if (this.ModuleControl is IAsyncModuleControl)
160160
{
161+
// We need to defer accesing this.Actions as it could only be accesible after the WebForms async point.
161162
this.Page.RegisterAsyncTask(new PageAsyncTask(this.ProcessActionsAsync));
162163
}
163164
else

0 commit comments

Comments
 (0)