Skip to content

Commit a565f10

Browse files
committed
257966: Parameterless overload of WebPage::ExecutePageHierarchy throws
when called.
1 parent 5391de5 commit a565f10

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

src/System.Web.WebPages/Resources/WebPageResources.Designer.cs

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/System.Web.WebPages/Resources/WebPageResources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@
216216
<data name="WebPage_CannotRequestDirectly" xml:space="preserve">
217217
<value>The file "{0}" cannot be requested directly because it calls the "{1}" method.</value>
218218
</data>
219+
<data name="WebPage_ExecutePageHierarchyCannotBeInvoked" xml:space="preserve">
220+
<value>ExecutePageHierarchy cannot be invoked if PageContext is null.</value>
221+
</data>
219222
<data name="WebPage_FileNotSupported" xml:space="preserve">
220223
<value>The following file could not be rendered because its extension "{0}" might not be supported: "{1}".</value>
221224
</data>

src/System.Web.WebPages/WebPage.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Diagnostics.CodeAnalysis;
33
using System.Linq;
44
using System.Web.WebPages.Html;
5+
using System.Web.WebPages.Resources;
56
using System.Web.WebPages.Scope;
67

78
namespace System.Web.WebPages
@@ -65,6 +66,11 @@ public static void RegisterPageExecutor(IWebPageRequestExecutor executor)
6566

6667
public override void ExecutePageHierarchy()
6768
{
69+
if (PageContext == null)
70+
{
71+
// The ExecutePageHierarchy in WebPageBase assumes a non-null PageContext.
72+
throw new InvalidOperationException(WebPageResources.WebPage_ExecutePageHierarchyCannotBeInvoked);
73+
}
6874
using (ScopeStorage.CreateTransientScope(new ScopeStorageDictionary(ScopeStorage.CurrentScope, PageData)))
6975
{
7076
ExecutePageHierarchy(_executors);

test/System.Web.WebPages.Test/WebPage/WebPageTest.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ public void CreatePageFromVirtualPathAssignsVirtualPathFactory()
3131
Assert.Equal(page.VirtualPath, path);
3232
}
3333

34+
[Fact]
35+
public void ExecutePageHierarchyThrowsIfPageContextIsNotSet()
36+
{
37+
// Arrange
38+
var page = new Mock<WebPage>() { CallBase = true };
39+
40+
// Act and Assert
41+
Assert.Throws<InvalidOperationException>(() => page.Object.ExecutePageHierarchy(), "ExecutePageHierarchy cannot be invoked if PageContext is null.");
42+
}
43+
3444
[Fact]
3545
public void NormalizeLayoutPagePathTest()
3646
{

0 commit comments

Comments
 (0)