Skip to content

[iOS] Fixed Webview LoadFile ignore directories. - #31040

Merged
kubaflo merged 11 commits into
dotnet:inflight/currentfrom
NirmalKumarYuvaraj:fix-23315
Jun 8, 2026
Merged

[iOS] Fixed Webview LoadFile ignore directories.#31040
kubaflo merged 11 commits into
dotnet:inflight/currentfrom
NirmalKumarYuvaraj:fix-23315

Conversation

@NirmalKumarYuvaraj

Copy link
Copy Markdown
Contributor

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Description of Change

This pull request addresses an issue where the WebView on iOS and macOS was unable to load files from subdirectories. The changes ensure that files located in nested directories can be accessed and displayed correctly in the WebView. The update includes both the necessary code fixes and new tests to verify the behavior.

WebView file loading improvements

  • Updated the LoadFile method in both WebViewHandler.iOS.cs and MauiWKWebView.cs to correctly handle file paths with subdirectories by using the appropriate NSBundle.GetUrlForResource overload, ensuring files in nested directories are found and loaded. [1] [2]

New test coverage

  • Added a new test case page Issue23315 that attempts to load an HTML file from a nested subdirectory to visually verify the fix.
  • Added the corresponding HTML test file in Resources/Raw/foo/bar/baz/test.html to serve as the content for the test.
  • Introduced a UITest Issue23315 that checks if the WebView successfully loads the file from the subdirectory and verifies the result with a screenshot.

Validated the behaviour in the following platforms

  • Android
  • Windows
  • iOS
  • Mac

Issues Fixed

Fixes #23315

Output

Before After
Before.mov
After.mov

@dotnet-policy-service dotnet-policy-service Bot added community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration labels Aug 6, 2025
@NirmalKumarYuvaraj
NirmalKumarYuvaraj marked this pull request as ready for review August 8, 2025 03:54
Copilot AI review requested due to automatic review settings August 8, 2025 03:54
@NirmalKumarYuvaraj
NirmalKumarYuvaraj requested a review from a team as a code owner August 8, 2025 03:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes an issue where WebView on iOS and macOS was unable to load files from subdirectories. The fix ensures that the LoadFile method correctly handles file paths with nested directories by using the appropriate NSBundle.GetUrlForResource overload.

  • Updated the LoadFile method in both WebViewHandler.iOS.cs and MauiWKWebView.cs to handle subdirectory paths
  • Added comprehensive test coverage with a UI test page and automated test
  • Included test HTML file in nested directory structure to validate the fix

Reviewed Changes

Copilot reviewed 5 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/Core/src/Platform/iOS/MauiWKWebView.cs Updated LoadFile method to handle subdirectories using NSBundle.GetUrlForResource overload
src/Core/src/Handlers/WebView/WebViewHandler.iOS.cs Applied same subdirectory handling fix to WebViewHandler
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue23315.cs Added automated UI test to verify WebView loads files from subdirectories
src/Controls/tests/TestCases.HostApp/Resources/Raw/foo/bar/baz/test.html Test HTML file in nested directory structure
src/Controls/tests/TestCases.HostApp/Issues/Issue23315.cs Test page UI that demonstrates loading file from subdirectory

Comment thread src/Core/src/Handlers/WebView/WebViewHandler.iOS.cs Outdated
Comment thread src/Core/src/Handlers/WebView/WebViewHandler.iOS.cs Outdated
@jfversluis

Copy link
Copy Markdown
Member

/azp run MAUI-UITests-public

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@jfversluis jfversluis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this still needs snapshots for macOS and maybe Windows? Ping me when you added those!

@jfversluis jfversluis added the s/pr-needs-author-input PR needs an update from the author label Dec 2, 2025
@NirmalKumarYuvaraj

Copy link
Copy Markdown
Contributor Author

@jfversluis , In the generated Images, the webview is not loaded. So I have increased the waiting interval. Works fine locally , almost renders instantly.

Mac Windows
WebViewCanLoadFileFromSubdirectory WebViewCanLoadFileFromSubdirectory

@dotnet-policy-service dotnet-policy-service Bot added the stale Indicates a stale issue/pr and will be closed soon label Dec 13, 2025
@sheiksyedm

Copy link
Copy Markdown
Contributor

/rebase

@sheiksyedm sheiksyedm removed the stale Indicates a stale issue/pr and will be closed soon label Dec 16, 2025
@dotnet-policy-service dotnet-policy-service Bot added the stale Indicates a stale issue/pr and will be closed soon label Dec 26, 2025
@sheiksyedm sheiksyedm removed s/pr-needs-author-input PR needs an update from the author stale Indicates a stale issue/pr and will be closed soon labels Dec 26, 2025
@MauiBot MauiBot added s/agent-changes-requested AI agent recommends changes - found a better alternative or issues s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review) labels Mar 21, 2026

@kubaflo kubaflo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please resolve conflicts?

@MauiBot MauiBot added the s/agent-fix-pr-picked AI could not beat the PR fix - PR is the best among all candidates label Mar 29, 2026
@kubaflo

kubaflo commented May 24, 2026

Copy link
Copy Markdown
Contributor

/review -b feature/refactor-copilot-yml

@MauiBot MauiBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expert Review — 2 findings

See inline comments for details.

[Category(UITestCategories.WebView)]
public void WebViewCanLoadFileFromSubdirectory()
{
App.WaitForElement("DescriptionLabel", timeout: TimeSpan.FromSeconds(5));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[moderate] Test Coverage — This waits for DescriptionLabel, which is outside the WebView and is present regardless of whether the local HTML ever loads. The screenshot can be captured before the WKWebView finishes rendering (or pass the precondition on a blank WebView), making the regression test flaky/weak for the actual fix. Please wait on WebView content or use a screenshot retry timeout tied to the HTML text being rendered.

@MauiBot MauiBot removed the s/agent-changes-requested AI agent recommends changes - found a better alternative or issues label May 24, 2026
@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 31040

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 31040"

@NirmalKumarYuvaraj

Copy link
Copy Markdown
Contributor Author

@kubaflo , Addressed AI summary concerns.

@kubaflo

kubaflo commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

/review -b feature/enhanced-reviewer -p ios

@MauiBot MauiBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expert Review — 3 findings

See inline comments for details.

/// <param name="url">The local file URL to load</param>
/// <param name="logger">Optional logger for error reporting</param>
/// <returns>True if the file was successfully loaded, false otherwise</returns>
internal static bool LoadFile(this WKWebView webView, string url, ILogger? logger = null)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[major] Backward Compatibility - This shared helper only fixes the handler path; the registered iOS compatibility WebView renderer still has the duplicated old LoadFile implementation that strips directories before calling NSBundle.MainBundle.GetUrlForResource(file, ext). Concrete scenario: an app using UseMauiCompatibility() or a compatibility WebView renderer with Source = foo/bar/baz/test.html on iOS/MacCatalyst still fails issue #23315. Please either reuse/apply the directory-preserving logic in src/Compatibility/Core/src/iOS/Renderers/WkWebViewRenderer.cs or explicitly scope this PR/test to handler-only behavior.

return false;
}

webView.LoadFileUrl(nsUrl, nsUrl);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[major] iOS/MacCatalyst WebView - LoadFileUrl(nsUrl, nsUrl) grants WKWebView read access only to the HTML file URL. Nested pages that load relative sibling resources (CSS/JS/images) from the same bundle directory can still render broken even though the top-level HTML loads. Use the containing directory or intended bundle root as allowingReadAccessToURL, and add coverage with a relative subresource under foo/bar/baz/.

// When the bug is present on iOS/MacCatalyst, LoadFile strips the directory part
// and tries to load only `test.html`, so the navigation fails and the label
// never reports the expected title.
var statusLabel = App.WaitForElement("StatusLabel", timeout: TimeSpan.FromSeconds(10));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[moderate] Regression Prevention - Waiting only for the StatusLabel element races the WebView navigation: the label exists as soon as the page is displayed, before Navigated updates it to Success. On slower iOS/MacCatalyst runs this can read the initial empty text and fail despite a correct fix. Wait for the label text to become Success before asserting.

@MauiBot MauiBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI Review Summary

@NirmalKumarYuvaraj — new AI review results are available based on this last commit: b0c18cb.
test modifications To request a fresh review after new comments or commits, comment /review rerun.

Gate Passed Code Review In Review Confidence Medium Platform iOS

Review Sessions — click to expand
Gate — Test Before & After Fix

Gate Result: ✅ PASSED

Platform: IOS · Base: main · Merge base: e904e900

Test Without Fix (expect FAIL) With Fix (expect PASS)
🖥️ Issue23315 Issue23315 ✅ FAIL — 332s ✅ PASS — 118s
🔴 Without fix — 🖥️ Issue23315: FAIL ✅ · 332s
  Determining projects to restore...
  Restored /Users/cloudtest/vss/_work/1/s/src/Controls/src/BindingSourceGen/Controls.BindingSourceGen.csproj (in 716 ms).
  Restored /Users/cloudtest/vss/_work/1/s/src/Graphics/src/Graphics/Graphics.csproj (in 1.12 sec).
  Restored /Users/cloudtest/vss/_work/1/s/src/Essentials/src/Essentials.csproj (in 4.57 sec).
  Restored /Users/cloudtest/vss/_work/1/s/src/Controls/Foldable/src/Controls.Foldable.csproj (in 6.11 sec).
  Restored /Users/cloudtest/vss/_work/1/s/src/Controls/src/Xaml/Controls.Xaml.csproj (in 6.13 sec).
  Restored /Users/cloudtest/vss/_work/1/s/src/Controls/tests/TestCases.HostApp/Controls.TestCases.HostApp.csproj (in 6.13 sec).
  Restored /Users/cloudtest/vss/_work/1/s/src/Core/maps/src/Maps.csproj (in 6.14 sec).
  Restored /Users/cloudtest/vss/_work/1/s/src/Core/src/Core.csproj (in 5.01 sec).
  Restored /Users/cloudtest/vss/_work/1/s/src/Controls/Maps/src/Controls.Maps.csproj (in 6.13 sec).
  Restored /Users/cloudtest/vss/_work/1/s/src/BlazorWebView/src/Maui/Microsoft.AspNetCore.Components.WebView.Maui.csproj (in 6.14 sec).
  Restored /Users/cloudtest/vss/_work/1/s/src/Controls/src/Core/Controls.Core.csproj (in 6.14 sec).
/Users/cloudtest/vss/_work/1/s/.dotnet/packs/Microsoft.iOS.Sdk.net10.0_26.0/26.0.11017/targets/Xamarin.Shared.Sdk.targets(309,3): warning : RuntimeIdentifier was set on the command line, and will override the value for RuntimeIdentifiers set in the project file. [/Users/cloudtest/vss/_work/1/s/src/Controls/tests/TestCases.HostApp/Controls.TestCases.HostApp.csproj::TargetFramework=net10.0-ios]
  ##vso[build.updatebuildnumber]10.0.80-ci+azdo.14309612
  Graphics -> /Users/cloudtest/vss/_work/1/s/artifacts/bin/Graphics/Debug/net10.0-ios26.0/Microsoft.Maui.Graphics.dll
  ##vso[build.updatebuildnumber]10.0.80-ci+azdo.14309612
  Essentials -> /Users/cloudtest/vss/_work/1/s/artifacts/bin/Essentials/Debug/net10.0-ios26.0/Microsoft.Maui.Essentials.dll
  ##vso[build.updatebuildnumber]10.0.80-ci+azdo.14309612
  Core -> /Users/cloudtest/vss/_work/1/s/artifacts/bin/Core/Debug/net10.0-ios26.0/Microsoft.Maui.dll
  ##vso[build.updatebuildnumber]10.0.80-ci+azdo.14309612
  Maps -> /Users/cloudtest/vss/_work/1/s/artifacts/bin/Maps/Debug/net10.0-ios26.0/Microsoft.Maui.Maps.dll
  Controls.BindingSourceGen -> /Users/cloudtest/vss/_work/1/s/artifacts/bin/Controls.BindingSourceGen/Debug/netstandard2.0/Microsoft.Maui.Controls.BindingSourceGen.dll
  ##vso[build.updatebuildnumber]10.0.80-ci+azdo.14309612
  Controls.Core -> /Users/cloudtest/vss/_work/1/s/artifacts/bin/Controls.Core/Debug/net10.0-ios26.0/Microsoft.Maui.Controls.dll
  ##vso[build.updatebuildnumber]10.0.80-ci+azdo.14309612
  ##vso[build.updatebuildnumber]10.0.80-ci+azdo.14309612
  ##vso[build.updatebuildnumber]10.0.80-ci+azdo.14309612
  ##vso[build.updatebuildnumber]10.0.80-ci+azdo.14309612
  Controls.Maps -> /Users/cloudtest/vss/_work/1/s/artifacts/bin/Controls.Maps/Debug/net10.0-ios26.0/Microsoft.Maui.Controls.Maps.dll
  Controls.Foldable -> /Users/cloudtest/vss/_work/1/s/artifacts/bin/Controls.Foldable/Debug/net10.0-ios26.0/Microsoft.Maui.Controls.Foldable.dll
  Controls.Xaml -> /Users/cloudtest/vss/_work/1/s/artifacts/bin/Controls.Xaml/Debug/net10.0-ios26.0/Microsoft.Maui.Controls.Xaml.dll
  Microsoft.AspNetCore.Components.WebView.Maui -> /Users/cloudtest/vss/_work/1/s/artifacts/bin/Microsoft.AspNetCore.Components.WebView.Maui/Debug/net10.0-ios26.0/Microsoft.AspNetCore.Components.WebView.Maui.dll
  Detected signing identity:
    Code Signing Key: "" (-)
    Provisioning Profile: "" () - no entitlements
    Bundle Id: com.microsoft.maui.uitests
    App Id: com.microsoft.maui.uitests
  Controls.TestCases.HostApp -> /Users/cloudtest/vss/_work/1/s/artifacts/bin/Controls.TestCases.HostApp/Debug/net10.0-ios/iossimulator-arm64/Controls.TestCases.HostApp.dll
  Optimizing assemblies for size may change the behavior of the app. Be sure to test after publishing. See: https://aka.ms/dotnet-illink
  Optimizing assemblies for size. This process might take a while.

Build succeeded.

/Users/cloudtest/vss/_work/1/s/.dotnet/packs/Microsoft.iOS.Sdk.net10.0_26.0/26.0.11017/targets/Xamarin.Shared.Sdk.targets(309,3): warning : RuntimeIdentifier was set on the command line, and will override the value for RuntimeIdentifiers set in the project file. [/Users/cloudtest/vss/_work/1/s/src/Controls/tests/TestCases.HostApp/Controls.TestCases.HostApp.csproj::TargetFramework=net10.0-ios]
    1 Warning(s)
    0 Error(s)

Time Elapsed 00:03:01.82
  Determining projects to restore...
  Restored /Users/cloudtest/vss/_work/1/s/src/Controls/src/BindingSourceGen/Controls.BindingSourceGen.csproj (in 779 ms).
  Restored /Users/cloudtest/vss/_work/1/s/src/Graphics/src/Graphics/Graphics.csproj (in 786 ms).
  Restored /Users/cloudtest/vss/_work/1/s/src/Controls/tests/CustomAttributes/Controls.CustomAttributes.csproj (in 779 ms).
  Restored /Users/cloudtest/vss/_work/1/s/src/Essentials/src/Essentials.csproj (in 786 ms).
  Restored /Users/cloudtest/vss/_work/1/s/src/TestUtils/src/VisualTestUtils/VisualTestUtils.csproj (in 1 ms).
  Restored /Users/cloudtest/vss/_work/1/s/src/TestUtils/src/UITest.Core/UITest.Core.csproj (in 1 ms).
  Restored /Users/cloudtest/vss/_work/1/s/src/Core/src/Core.csproj (in 914 ms).
  Restored /Users/cloudtest/vss/_work/1/s/src/Controls/src/Core/Controls.Core.csproj (in 929 ms).
  Restored /Users/cloudtest/vss/_work/1/s/src/TestUtils/src/UITest.NUnit/UITest.NUnit.csproj (in 1.68 sec).
  Restored /Users/cloudtest/vss/_work/1/s/src/TestUtils/src/UITest.Appium/UITest.Appium.csproj (in 1.93 sec).
  Restored /Users/cloudtest/vss/_work/1/s/src/TestUtils/src/UITest.Analyzers/UITest.Analyzers.csproj (in 4.4 sec).
  Restored /Users/cloudtest/vss/_work/1/s/src/TestUtils/src/VisualTestUtils.MagickNet/VisualTestUtils.MagickNet.csproj (in 5.52 sec).
  Restored /Users/cloudtest/vss/_work/1/s/src/Controls/tests/TestCases.iOS.Tests/Controls.TestCases.iOS.Tests.csproj (in 6.37 sec).
  ##vso[build.updatebuildnumber]10.0.80-ci+azdo.14309612
  Controls.CustomAttributes -> /Users/cloudtest/vss/_work/1/s/artifacts/bin/Controls.CustomAttributes/Debug/net10.0/Controls.CustomAttributes.dll
  Graphics -> /Users/cloudtest/vss/_work/1/s/artifacts/bin/Graphics/Debug/net10.0/Microsoft.Maui.Graphics.dll
  ##vso[build.updatebuildnumber]10.0.80-ci+azdo.14309612
  Essentials -> /Users/cloudtest/vss/_work/1/s/artifacts/bin/Essentials/Debug/net10.0/Microsoft.Maui.Essentials.dll
  ##vso[build.updatebuildnumber]10.0.80-ci+azdo.14309612
  Core -> /Users/cloudtest/vss/_work/1/s/artifacts/bin/Core/Debug/net10.0/Microsoft.Maui.dll
  Controls.BindingSourceGen -> /Users/cloudtest/vss/_work/1/s/artifacts/bin/Controls.BindingSourceGen/Debug/netstandard2.0/Microsoft.Maui.Controls.BindingSourceGen.dll
  ##vso[build.updatebuildnumber]10.0.80-ci+azdo.14309612
  Controls.Core -> /Users/cloudtest/vss/_work/1/s/artifacts/bin/Controls.Core/Debug/net10.0/Microsoft.Maui.Controls.dll
  UITest.Core -> /Users/cloudtest/vss/_work/1/s/artifacts/bin/UITest.Core/Debug/net10.0/UITest.Core.dll
  VisualTestUtils -> /Users/cloudtest/vss/_work/1/s/artifacts/bin/VisualTestUtils/Debug/netstandard2.0/VisualTestUtils.dll
  VisualTestUtils.MagickNet -> /Users/cloudtest/vss/_work/1/s/artifacts/bin/VisualTestUtils.MagickNet/Debug/netstandard2.0/VisualTestUtils.MagickNet.dll
  UITest.NUnit -> /Users/cloudtest/vss/_work/1/s/artifacts/bin/UITest.NUnit/Debug/net10.0/UITest.NUnit.dll
  UITest.Appium -> /Users/cloudtest/vss/_work/1/s/artifacts/bin/UITest.Appium/Debug/net10.0/UITest.Appium.dll
  UITest.Analyzers -> /Users/cloudtest/vss/_work/1/s/artifacts/bin/UITest.Analyzers/Debug/netstandard2.0/UITest.Analyzers.dll
  Controls.TestCases.iOS.Tests -> /Users/cloudtest/vss/_work/1/s/artifacts/bin/Controls.TestCases.iOS.Tests/Debug/net10.0/Controls.TestCases.iOS.Tests.dll
Test run for /Users/cloudtest/vss/_work/1/s/artifacts/bin/Controls.TestCases.iOS.Tests/Debug/net10.0/Controls.TestCases.iOS.Tests.dll (.NETCoreApp,Version=v10.0)
VSTest version 18.0.1 (arm64)

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
[xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v2.8.2+699d445a1a (64-bit .NET 10.0.0)
[xUnit.net 00:00:00.07]   Discovering: Controls.TestCases.iOS.Tests
[xUnit.net 00:00:00.21]   Discovered:  Controls.TestCases.iOS.Tests
NUnit Adapter 4.5.0.0: Test execution started
Running selected tests in /Users/cloudtest/vss/_work/1/s/artifacts/bin/Controls.TestCases.iOS.Tests/Debug/net10.0/Controls.TestCases.iOS.Tests.dll
   NUnit3TestExecutor discovered 1 of 1 NUnit test cases using Current Discovery mode, Non-Explicit run
>>>>> 6/8/2026 3:59:49 AM FixtureSetup for Issue23315(iOS)
>>>>> 6/8/2026 3:59:54 AM WebViewCanLoadFileFromSubdirectory Start
>>>>> 6/8/2026 4:00:04 AM WebViewCanLoadFileFromSubdirectory Stop
>>>>> 6/8/2026 4:00:04 AM Log types: syslog, crashlog, performance, safariConsole, safariNetwork, server
  Failed WebViewCanLoadFileFromSubdirectory [10 s]
  Error Message:
   System.TimeoutException : Timed out waiting for element...
  Stack Trace:
     at UITest.Appium.HelperExtensions.Wait(Func`1 query, Func`2 satisfactory, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2757
   at UITest.Appium.HelperExtensions.WaitForAtLeastOne(Func`1 query, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2784
   at UITest.Appium.HelperExtensions.WaitForElement(IApp app, String marked, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency, Nullable`1 postTimeout) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 793
   at Microsoft.Maui.TestCases.Tests.Issues.Issue23315.WebViewCanLoadFileFromSubdirectory() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue23315.cs:line 19
   at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

NUnit Adapter 4.5.0.0: Test execution complete
Results File: /Users/cloudtest/vss/_work/1/s/CustomAgentLogsTmp/UITests/TestResults/Issue23315.trx

Total tests: 1
     Failed: 1
Test Run Failed.
 Total time: 1.5770 Minutes
>>> TRX_RESULT_FILE: /Users/cloudtest/vss/_work/1/s/CustomAgentLogsTmp/UITests/TestResults/Issue23315.trx

🟢 With fix — 🖥️ Issue23315: PASS ✅ · 118s
  Determining projects to restore...
  Restored /Users/cloudtest/vss/_work/1/s/src/Controls/src/BindingSourceGen/Controls.BindingSourceGen.csproj (in 435 ms).
  Restored /Users/cloudtest/vss/_work/1/s/src/Graphics/src/Graphics/Graphics.csproj (in 408 ms).
  Restored /Users/cloudtest/vss/_work/1/s/src/Essentials/src/Essentials.csproj (in 462 ms).
  Restored /Users/cloudtest/vss/_work/1/s/src/Controls/src/Core/Controls.Core.csproj (in 507 ms).
  Restored /Users/cloudtest/vss/_work/1/s/src/Core/src/Core.csproj (in 523 ms).
  6 of 11 projects are up-to-date for restore.
/Users/cloudtest/vss/_work/1/s/.dotnet/packs/Microsoft.iOS.Sdk.net10.0_26.0/26.0.11017/targets/Xamarin.Shared.Sdk.targets(309,3): warning : RuntimeIdentifier was set on the command line, and will override the value for RuntimeIdentifiers set in the project file. [/Users/cloudtest/vss/_work/1/s/src/Controls/tests/TestCases.HostApp/Controls.TestCases.HostApp.csproj::TargetFramework=net10.0-ios]
  ##vso[build.updatebuildnumber]10.0.80-ci+azdo.14309612
  Graphics -> /Users/cloudtest/vss/_work/1/s/artifacts/bin/Graphics/Debug/net10.0-ios26.0/Microsoft.Maui.Graphics.dll
  ##vso[build.updatebuildnumber]10.0.80-ci+azdo.14309612
  Essentials -> /Users/cloudtest/vss/_work/1/s/artifacts/bin/Essentials/Debug/net10.0-ios26.0/Microsoft.Maui.Essentials.dll
  ##vso[build.updatebuildnumber]10.0.80-ci+azdo.14309612
  Core -> /Users/cloudtest/vss/_work/1/s/artifacts/bin/Core/Debug/net10.0-ios26.0/Microsoft.Maui.dll
  ##vso[build.updatebuildnumber]10.0.80-ci+azdo.14309612
  Maps -> /Users/cloudtest/vss/_work/1/s/artifacts/bin/Maps/Debug/net10.0-ios26.0/Microsoft.Maui.Maps.dll
  Controls.BindingSourceGen -> /Users/cloudtest/vss/_work/1/s/artifacts/bin/Controls.BindingSourceGen/Debug/netstandard2.0/Microsoft.Maui.Controls.BindingSourceGen.dll
  ##vso[build.updatebuildnumber]10.0.80-ci+azdo.14309612
  Controls.Core -> /Users/cloudtest/vss/_work/1/s/artifacts/bin/Controls.Core/Debug/net10.0-ios26.0/Microsoft.Maui.Controls.dll
  ##vso[build.updatebuildnumber]10.0.80-ci+azdo.14309612
  ##vso[build.updatebuildnumber]10.0.80-ci+azdo.14309612
  ##vso[build.updatebuildnumber]10.0.80-ci+azdo.14309612
  ##vso[build.updatebuildnumber]10.0.80-ci+azdo.14309612
  Microsoft.AspNetCore.Components.WebView.Maui -> /Users/cloudtest/vss/_work/1/s/artifacts/bin/Microsoft.AspNetCore.Components.WebView.Maui/Debug/net10.0-ios26.0/Microsoft.AspNetCore.Components.WebView.Maui.dll
  Controls.Maps -> /Users/cloudtest/vss/_work/1/s/artifacts/bin/Controls.Maps/Debug/net10.0-ios26.0/Microsoft.Maui.Controls.Maps.dll
  Controls.Xaml -> /Users/cloudtest/vss/_work/1/s/artifacts/bin/Controls.Xaml/Debug/net10.0-ios26.0/Microsoft.Maui.Controls.Xaml.dll
  Controls.Foldable -> /Users/cloudtest/vss/_work/1/s/artifacts/bin/Controls.Foldable/Debug/net10.0-ios26.0/Microsoft.Maui.Controls.Foldable.dll
  Detected signing identity:
    Code Signing Key: "" (-)
    Provisioning Profile: "" () - no entitlements
    Bundle Id: com.microsoft.maui.uitests
    App Id: com.microsoft.maui.uitests
  Controls.TestCases.HostApp -> /Users/cloudtest/vss/_work/1/s/artifacts/bin/Controls.TestCases.HostApp/Debug/net10.0-ios/iossimulator-arm64/Controls.TestCases.HostApp.dll
  Optimizing assemblies for size may change the behavior of the app. Be sure to test after publishing. See: https://aka.ms/dotnet-illink
  Optimizing assemblies for size. This process might take a while.

Build succeeded.

/Users/cloudtest/vss/_work/1/s/.dotnet/packs/Microsoft.iOS.Sdk.net10.0_26.0/26.0.11017/targets/Xamarin.Shared.Sdk.targets(309,3): warning : RuntimeIdentifier was set on the command line, and will override the value for RuntimeIdentifiers set in the project file. [/Users/cloudtest/vss/_work/1/s/src/Controls/tests/TestCases.HostApp/Controls.TestCases.HostApp.csproj::TargetFramework=net10.0-ios]
    1 Warning(s)
    0 Error(s)

Time Elapsed 00:01:00.73
  Determining projects to restore...
  Restored /Users/cloudtest/vss/_work/1/s/src/Controls/src/BindingSourceGen/Controls.BindingSourceGen.csproj (in 398 ms).
  Restored /Users/cloudtest/vss/_work/1/s/src/Graphics/src/Graphics/Graphics.csproj (in 362 ms).
  Restored /Users/cloudtest/vss/_work/1/s/src/Essentials/src/Essentials.csproj (in 361 ms).
  Restored /Users/cloudtest/vss/_work/1/s/src/Controls/src/Core/Controls.Core.csproj (in 434 ms).
  Restored /Users/cloudtest/vss/_work/1/s/src/Core/src/Core.csproj (in 451 ms).
  8 of 13 projects are up-to-date for restore.
  ##vso[build.updatebuildnumber]10.0.80-ci+azdo.14309612
  Controls.CustomAttributes -> /Users/cloudtest/vss/_work/1/s/artifacts/bin/Controls.CustomAttributes/Debug/net10.0/Controls.CustomAttributes.dll
  Graphics -> /Users/cloudtest/vss/_work/1/s/artifacts/bin/Graphics/Debug/net10.0/Microsoft.Maui.Graphics.dll
  ##vso[build.updatebuildnumber]10.0.80-ci+azdo.14309612
  Essentials -> /Users/cloudtest/vss/_work/1/s/artifacts/bin/Essentials/Debug/net10.0/Microsoft.Maui.Essentials.dll
  ##vso[build.updatebuildnumber]10.0.80-ci+azdo.14309612
  Core -> /Users/cloudtest/vss/_work/1/s/artifacts/bin/Core/Debug/net10.0/Microsoft.Maui.dll
  Controls.BindingSourceGen -> /Users/cloudtest/vss/_work/1/s/artifacts/bin/Controls.BindingSourceGen/Debug/netstandard2.0/Microsoft.Maui.Controls.BindingSourceGen.dll
  ##vso[build.updatebuildnumber]10.0.80-ci+azdo.14309612
  Controls.Core -> /Users/cloudtest/vss/_work/1/s/artifacts/bin/Controls.Core/Debug/net10.0/Microsoft.Maui.Controls.dll
  VisualTestUtils -> /Users/cloudtest/vss/_work/1/s/artifacts/bin/VisualTestUtils/Debug/netstandard2.0/VisualTestUtils.dll
  UITest.Core -> /Users/cloudtest/vss/_work/1/s/artifacts/bin/UITest.Core/Debug/net10.0/UITest.Core.dll
  VisualTestUtils.MagickNet -> /Users/cloudtest/vss/_work/1/s/artifacts/bin/VisualTestUtils.MagickNet/Debug/netstandard2.0/VisualTestUtils.MagickNet.dll
  UITest.NUnit -> /Users/cloudtest/vss/_work/1/s/artifacts/bin/UITest.NUnit/Debug/net10.0/UITest.NUnit.dll
  UITest.Appium -> /Users/cloudtest/vss/_work/1/s/artifacts/bin/UITest.Appium/Debug/net10.0/UITest.Appium.dll
  UITest.Analyzers -> /Users/cloudtest/vss/_work/1/s/artifacts/bin/UITest.Analyzers/Debug/netstandard2.0/UITest.Analyzers.dll
  Controls.TestCases.iOS.Tests -> /Users/cloudtest/vss/_work/1/s/artifacts/bin/Controls.TestCases.iOS.Tests/Debug/net10.0/Controls.TestCases.iOS.Tests.dll
Test run for /Users/cloudtest/vss/_work/1/s/artifacts/bin/Controls.TestCases.iOS.Tests/Debug/net10.0/Controls.TestCases.iOS.Tests.dll (.NETCoreApp,Version=v10.0)
VSTest version 18.0.1 (arm64)

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
[xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v2.8.2+699d445a1a (64-bit .NET 10.0.0)
[xUnit.net 00:00:00.05]   Discovering: Controls.TestCases.iOS.Tests
[xUnit.net 00:00:00.19]   Discovered:  Controls.TestCases.iOS.Tests
NUnit Adapter 4.5.0.0: Test execution started
Running selected tests in /Users/cloudtest/vss/_work/1/s/artifacts/bin/Controls.TestCases.iOS.Tests/Debug/net10.0/Controls.TestCases.iOS.Tests.dll
   NUnit3TestExecutor discovered 1 of 1 NUnit test cases using Current Discovery mode, Non-Explicit run
>>>>> 6/8/2026 4:01:57 AM FixtureSetup for Issue23315(iOS)
>>>>> 6/8/2026 4:02:01 AM WebViewCanLoadFileFromSubdirectory Start
>>>>> 6/8/2026 4:02:03 AM WebViewCanLoadFileFromSubdirectory Stop
  Passed WebViewCanLoadFileFromSubdirectory [2 s]
NUnit Adapter 4.5.0.0: Test execution complete
Results File: /Users/cloudtest/vss/_work/1/s/CustomAgentLogsTmp/UITests/TestResults/Issue23315.trx

Test Run Successful.
Total tests: 1
     Passed: 1
 Total time: 24.5224 Seconds
>>> TRX_RESULT_FILE: /Users/cloudtest/vss/_work/1/s/CustomAgentLogsTmp/UITests/TestResults/Issue23315.trx

📁 Fix files reverted (7 files)
  • eng/pipelines/ci-copilot.yml
  • eng/pipelines/common/variables.yml
  • src/Core/src/Handlers/HybridWebView/HybridWebView.js
  • src/Core/src/Handlers/HybridWebView/HybridWebView.ts
  • src/Core/src/Handlers/WebView/WebViewHandler.iOS.cs
  • src/Core/src/Platform/iOS/MauiWKWebView.cs
  • src/Core/src/Platform/iOS/WebViewExtensions.cs

UI Tests — ViewBaseTests,WebView

Detected UI test categories: ViewBaseTests,WebView


Pre-Flight — Context & Validation

Issue: #23315 - LoadFile in src/Core/src/Platform/iOS/MauiWKWebView.cs ignore directories.
PR: #31040 - [iOS] Fixed Webview LoadFile ignore directories.
Platforms Affected: iOS, MacCatalyst/macOS
Files Changed: 3 implementation, 3 test

Key Findings

  • Issue #23315 reports that WebView.Source = "foo/bar.html" on MacCatalyst is treated as bar.html because the iOS/MacCatalyst local-file loader strips the directory before querying NSBundle.
  • PR #31040 moves duplicated local bundled-file loading into WebViewExtensions.LoadFile, preserving Path.GetDirectoryName(url) and using NSBundle.MainBundle.GetUrlForResource(file, ext, directory) for nested resources.
  • Added UI coverage exercises foo/bar/baz/test.html through the WebView issue test page.
  • Existing gate result supplied by caller: Gate ✅ PASSED — tests fail without fix and pass with fix.

Code Review Summary

Verdict: NEEDS_CHANGES
Confidence: medium-high
Errors: 1 | Warnings: 1 | Suggestions: 1

Key code review findings:

  • src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue23315.cs:19 waits only for StatusLabel existence, not for navigation completion/Success, so the UI test can be flaky.
  • ⚠️ src/Compatibility/Core/src/iOS/Renderers/WkWebViewRenderer.cs:219 still ignores directories in compatibility WebView rendering.
  • 💡 src/Core/src/Platform/iOS/WebViewExtensions.cs:172 should consider testing relative subresources under nested HTML and using directory read access if needed.

Failure-mode probes:

  • Source = "foo/bar/baz/test.html" loads after navigation completes.
  • Nested HTML with relative sibling CSS/images/scripts renders.
  • Root-level Source = "test.html" still loads.
  • Compatibility renderer parity is either fixed or explicitly scoped out.
  • MacCatalyst bundle resource lookup works for nested Resources/Raw/**.

Blast radius: iOS/MacCatalyst WebView handler local bundled-file loading, including first-load and subsequent-load paths; WebView UI test category.

Fix Candidates

# Source Approach Test Result Files Changed Notes
PR PR #31040 Shared WKWebView helper keeps directory component and resolves nested bundled resources with NSBundle.GetUrlForResource(file, ext, directory) ✅ PASSED (Gate) WebViewHandler.iOS.cs, MauiWKWebView.cs, WebViewExtensions.cs, UI test files Original PR

Code Review — Deep Analysis

Code Review — PR #31040

Verdict: NEEDS_CHANGES

Confidence: medium-high

Independent Assessment

What this changes: iOS/MacCatalyst WebView local-file loading now factors Path.GetDirectoryName(url) and calls NSBundle.MainBundle.GetUrlForResource(file, ext, directory) for nested bundled resources. The duplicated handler/platform-view logic was moved into WebViewExtensions.LoadFile.

Inferred motivation: Fix WebView.Source = "foo/bar/baz/test.html" where old code stripped directories and searched only for test.html.

Reconciliation with PR Narrative

The implementation matches the stated issue for modern handlers. However, test coverage is still not deterministic, and compatibility renderer behavior remains unfixed.

Findings

❌ Error — UI test can read the status before navigation completes

src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue23315.cs:19

The test only waits for StatusLabel to exist, then immediately reads its text. The label exists before WebView.Navigated fires, so this can return empty/null and fail even when the product fix works. It should wait for the expected state, e.g. App.WaitForTextToBePresentInElement("StatusLabel", "Success", timeout: ...), or otherwise synchronize on navigation completion.

⚠️ Warning — Compatibility renderer still has the old bug

src/Compatibility/Core/src/iOS/Renderers/WkWebViewRenderer.cs:219

The obsolete-but-supported compatibility WkWebViewRenderer still uses NSBundle.MainBundle.GetUrlForResource(file, ext) and ignores directories. Apps still using compatibility renderers will continue to fail the same nested-file scenario. Either route it through the new helper or explicitly document that the fix is handler-only.

💡 Suggestion — Probe relative subresources under nested HTML

src/Core/src/Platform/iOS/WebViewExtensions.cs:172

LoadFileUrl(nsUrl, nsUrl) grants read access only to the file URL. If the nested HTML references sibling CSS/images/scripts, WKWebView may not be able to load them. Add a failure-mode test with a relative sibling asset, and if needed pass the containing directory as allowingReadAccessToURL.

Blast Radius

  • iOS + MacCatalyst WebView handler local bundled-file loading.
  • First-load and subsequent-load paths (WebViewHandler and MauiWKWebView) both use the helper.
  • Compatibility renderer path remains a separate behavioral surface.
  • UI test category: WebView; affected platforms primarily iOS/MacCatalyst.

Failure-Mode Probes

  • Source = "foo/bar/baz/test.html" loads successfully after navigation completes.
  • Same nested file with relative ./style.css or image renders.
  • Plain root file Source = "test.html" still loads.
  • Compatibility renderer WebView with nested local file, if parity is required.
  • MacCatalyst bundle resource lookup with nested Resources/Raw/** logical names.

Devil's Advocate

The core helper is small and likely correct for the modern handler scenario. The main blocker is test determinism: current coverage can fail before the async navigation event updates the label, so it does not provide reliable regression protection. The compatibility renderer gap may be acceptable only if maintainers explicitly decide this fix does not apply to obsolete renderers.


Fix — Analysis & Comparison

Fix Candidates

# Source Approach Test Result Files Changed Notes
1 try-fix-1 Resolve local file sources as bundle-relative paths, reject path traversal/rooted paths, load with read access to the containing directory, and reuse the helper for handler and compatibility renderer paths. PASS 4 files Broader than PR: preserves requested path, supports same-directory subresources, and fixes compatibility renderer parity.
PR PR #31040 Shared WKWebView helper keeps directory component and resolves nested bundled resources with NSBundle.GetUrlForResource(file, ext, directory). PASS (Gate) 3 implementation files plus UI test files Original PR; leaves compatibility renderer unchanged and uses the file URL as read-access URL.

Cross-Pollination

Model Round New Ideas? Details
maui-expert-reviewer 1 Yes Suggested bundle-relative path resolution with containing-directory read access and compatibility renderer reuse.

Exhausted: No - stopped because Candidate #1 passed the targeted iOS regression and is demonstrably better than the PR's current fix.
Selected Fix: Candidate #1 - It passes the iOS Issue23315 regression command and covers two gaps in the PR approach: relative nested subresource read access and compatibility renderer parity.


Report — Final Recommendation

Comparative Report — PR #31040

Candidates compared

Rank Candidate Regression result Assessment
1 pr-plus-reviewer Not rerun; based on PR gate PASS plus expert-review sandbox feedback Best overall. Keeps the PR's passing NSBundle.GetUrlForResource(file, ext, directory) approach while adding compatibility renderer parity, containing-directory read access, and a non-racy UI assertion.
2 try-fix-1 PASS — Issue23315 iOS HostApp UI test Strong alternative implementation. It resolves sources as bundle-relative file paths, rejects rooted/path-traversal inputs, grants containing-directory read access, and fixes compatibility renderer parity. It ranks below pr-plus-reviewer because it replaces NSBundle lookup with direct bundle-path resolution, which the try-fix notes identify as a compatibility risk for bundle resource semantics.
3 pr PASS — supplied gate result Correctly fixes the reported handler-path regression for nested bundled HTML, but ranks below the two improved candidates because it leaves compatibility WebView broken, grants read access only to the HTML file, and has a flaky UI test wait.

Candidate details

pr

The submitted PR centralizes handler local-file loading into WebViewExtensions.LoadFile, preserves Path.GetDirectoryName(url), and uses NSBundle.MainBundle.GetUrlForResource(file, ext, directory). The supplied gate passed: the new iOS Issue23315 test fails without the fix and passes with the fix.

However, the expert review found three gaps: compatibility WkWebViewRenderer still strips directories, LoadFileUrl(nsUrl, nsUrl) may block relative sibling resources, and the UI test waits for element existence rather than the Success state.

pr-plus-reviewer

This candidate applies the expert reviewer's actionable feedback in a sandbox form while preserving the PR's core strategy. It fixes compatibility renderer parity by reusing the shared helper, broadens WKWebView read access to the containing directory, and makes the regression test wait for navigation success.

This is the best balance of correctness and risk: it addresses every expert-review finding without switching away from NSBundle resource lookup.

try-fix-1

try-fix-1 passed the targeted iOS regression test and is a credible broader fix. It directly resolves the requested source against NSBundle.MainBundle.BundlePath, rejects unsafe rooted/path-traversal inputs, verifies file existence, grants read access to the containing directory, and reuses the helper from handler and compatibility renderer paths.

Its main drawback is the one documented in its own result file: direct bundle path resolution bypasses NSBundle localization/resource lookup semantics. That risk is acceptable for many Resources/Raw cases, but it is broader than needed when pr-plus-reviewer can fix the same reviewer gaps while preserving the PR's NSBundle behavior.

Winner

Winner: pr-plus-reviewer

pr-plus-reviewer wins because it combines the submitted PR's passing fix and lower-risk bundle resource lookup with the expert reviewer's required improvements. No candidate failed regression tests; among the candidates that passed or build on a passing result, pr-plus-reviewer has the best correctness/risk tradeoff.


Future Action — review latest findings

No alternative fix was selected for this run. Review the session findings and CI results before merging.

@kubaflo
kubaflo changed the base branch from main to inflight/current June 8, 2026 15:10
@kubaflo
kubaflo merged commit d63ccb3 into dotnet:inflight/current Jun 8, 2026
31 of 34 checks passed
@github-actions github-actions Bot added this to the .NET 10.0 SR8 milestone Jun 8, 2026
PureWeen pushed a commit that referenced this pull request Jun 11, 2026
<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Description of Change

<!-- Enter description of the fix in this section -->
This pull request addresses an issue where the WebView on iOS and macOS
was unable to load files from subdirectories. The changes ensure that
files located in nested directories can be accessed and displayed
correctly in the WebView. The update includes both the necessary code
fixes and new tests to verify the behavior.

### WebView file loading improvements

* Updated the `LoadFile` method in both `WebViewHandler.iOS.cs` and
`MauiWKWebView.cs` to correctly handle file paths with subdirectories by
using the appropriate `NSBundle.GetUrlForResource` overload, ensuring
files in nested directories are found and loaded.
[[1]](diffhunk://#diff-b752aea5c6f8159ab0eea93a14b8b0fb0653d3fb30daaed38df5653bcd2f2bdcR513-R520)
[[2]](diffhunk://#diff-c0e04ad305434c245715d87f41af80af7482f37d7e8413fdeaffcad220c8e2dbR189-R196)

### New test coverage

* Added a new test case page `Issue23315` that attempts to load an HTML
file from a nested subdirectory to visually verify the fix.
* Added the corresponding HTML test file in
`Resources/Raw/foo/bar/baz/test.html` to serve as the content for the
test.
* Introduced a UITest `Issue23315` that checks if the WebView
successfully loads the file from the subdirectory and verifies the
result with a screenshot.

Validated the behaviour in the following platforms

- [x] Android
- [ ] Windows
- [x] iOS
- [x] Mac


### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #23315

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->

### Output
| Before| After|
|--|--|
| <video
src="https://github.com/user-attachments/assets/70ca7082-d50e-44e3-a6d3-c2f84e40317c">
| <video
src="https://github.com/user-attachments/assets/2cbf6baa-6da6-444e-983f-76cd922f9e28">
|

---------
@sheiksyedm sheiksyedm modified the milestones: .NET 10 SR8, .NET 10 SR9 Jun 18, 2026
PureWeen pushed a commit that referenced this pull request Jun 22, 2026
<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Description of Change

<!-- Enter description of the fix in this section -->
This pull request addresses an issue where the WebView on iOS and macOS
was unable to load files from subdirectories. The changes ensure that
files located in nested directories can be accessed and displayed
correctly in the WebView. The update includes both the necessary code
fixes and new tests to verify the behavior.

### WebView file loading improvements

* Updated the `LoadFile` method in both `WebViewHandler.iOS.cs` and
`MauiWKWebView.cs` to correctly handle file paths with subdirectories by
using the appropriate `NSBundle.GetUrlForResource` overload, ensuring
files in nested directories are found and loaded.
[[1]](diffhunk://#diff-b752aea5c6f8159ab0eea93a14b8b0fb0653d3fb30daaed38df5653bcd2f2bdcR513-R520)
[[2]](diffhunk://#diff-c0e04ad305434c245715d87f41af80af7482f37d7e8413fdeaffcad220c8e2dbR189-R196)

### New test coverage

* Added a new test case page `Issue23315` that attempts to load an HTML
file from a nested subdirectory to visually verify the fix.
* Added the corresponding HTML test file in
`Resources/Raw/foo/bar/baz/test.html` to serve as the content for the
test.
* Introduced a UITest `Issue23315` that checks if the WebView
successfully loads the file from the subdirectory and verifies the
result with a screenshot.

Validated the behaviour in the following platforms

- [x] Android
- [ ] Windows
- [x] iOS
- [x] Mac


### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #23315

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->

### Output
| Before| After|
|--|--|
| <video
src="https://github.com/user-attachments/assets/70ca7082-d50e-44e3-a6d3-c2f84e40317c">
| <video
src="https://github.com/user-attachments/assets/2cbf6baa-6da6-444e-983f-76cd922f9e28">
|

---------
kubaflo pushed a commit that referenced this pull request Jun 25, 2026
<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Description of Change

<!-- Enter description of the fix in this section -->
This pull request addresses an issue where the WebView on iOS and macOS
was unable to load files from subdirectories. The changes ensure that
files located in nested directories can be accessed and displayed
correctly in the WebView. The update includes both the necessary code
fixes and new tests to verify the behavior.

### WebView file loading improvements

* Updated the `LoadFile` method in both `WebViewHandler.iOS.cs` and
`MauiWKWebView.cs` to correctly handle file paths with subdirectories by
using the appropriate `NSBundle.GetUrlForResource` overload, ensuring
files in nested directories are found and loaded.
[[1]](diffhunk://#diff-b752aea5c6f8159ab0eea93a14b8b0fb0653d3fb30daaed38df5653bcd2f2bdcR513-R520)
[[2]](diffhunk://#diff-c0e04ad305434c245715d87f41af80af7482f37d7e8413fdeaffcad220c8e2dbR189-R196)

### New test coverage

* Added a new test case page `Issue23315` that attempts to load an HTML
file from a nested subdirectory to visually verify the fix.
* Added the corresponding HTML test file in
`Resources/Raw/foo/bar/baz/test.html` to serve as the content for the
test.
* Introduced a UITest `Issue23315` that checks if the WebView
successfully loads the file from the subdirectory and verifies the
result with a screenshot.

Validated the behaviour in the following platforms

- [x] Android
- [ ] Windows
- [x] iOS
- [x] Mac


### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #23315

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->

### Output
| Before| After|
|--|--|
| <video
src="https://github.com/user-attachments/assets/70ca7082-d50e-44e3-a6d3-c2f84e40317c">
| <video
src="https://github.com/user-attachments/assets/2cbf6baa-6da6-444e-983f-76cd922f9e28">
|

---------
kubaflo pushed a commit that referenced this pull request Jul 3, 2026
<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Description of Change

<!-- Enter description of the fix in this section -->
This pull request addresses an issue where the WebView on iOS and macOS
was unable to load files from subdirectories. The changes ensure that
files located in nested directories can be accessed and displayed
correctly in the WebView. The update includes both the necessary code
fixes and new tests to verify the behavior.

### WebView file loading improvements

* Updated the `LoadFile` method in both `WebViewHandler.iOS.cs` and
`MauiWKWebView.cs` to correctly handle file paths with subdirectories by
using the appropriate `NSBundle.GetUrlForResource` overload, ensuring
files in nested directories are found and loaded.
[[1]](diffhunk://#diff-b752aea5c6f8159ab0eea93a14b8b0fb0653d3fb30daaed38df5653bcd2f2bdcR513-R520)
[[2]](diffhunk://#diff-c0e04ad305434c245715d87f41af80af7482f37d7e8413fdeaffcad220c8e2dbR189-R196)

### New test coverage

* Added a new test case page `Issue23315` that attempts to load an HTML
file from a nested subdirectory to visually verify the fix.
* Added the corresponding HTML test file in
`Resources/Raw/foo/bar/baz/test.html` to serve as the content for the
test.
* Introduced a UITest `Issue23315` that checks if the WebView
successfully loads the file from the subdirectory and verifies the
result with a screenshot.

Validated the behaviour in the following platforms

- [x] Android
- [ ] Windows
- [x] iOS
- [x] Mac


### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #23315

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->

### Output
| Before| After|
|--|--|
| <video
src="https://github.com/user-attachments/assets/70ca7082-d50e-44e3-a6d3-c2f84e40317c">
| <video
src="https://github.com/user-attachments/assets/2cbf6baa-6da6-444e-983f-76cd922f9e28">
|

---------
@kubaflo kubaflo mentioned this pull request Jul 6, 2026
kubaflo pushed a commit that referenced this pull request Jul 6, 2026
<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Description of Change

<!-- Enter description of the fix in this section -->
This pull request addresses an issue where the WebView on iOS and macOS
was unable to load files from subdirectories. The changes ensure that
files located in nested directories can be accessed and displayed
correctly in the WebView. The update includes both the necessary code
fixes and new tests to verify the behavior.

### WebView file loading improvements

* Updated the `LoadFile` method in both `WebViewHandler.iOS.cs` and
`MauiWKWebView.cs` to correctly handle file paths with subdirectories by
using the appropriate `NSBundle.GetUrlForResource` overload, ensuring
files in nested directories are found and loaded.
[[1]](diffhunk://#diff-b752aea5c6f8159ab0eea93a14b8b0fb0653d3fb30daaed38df5653bcd2f2bdcR513-R520)
[[2]](diffhunk://#diff-c0e04ad305434c245715d87f41af80af7482f37d7e8413fdeaffcad220c8e2dbR189-R196)

### New test coverage

* Added a new test case page `Issue23315` that attempts to load an HTML
file from a nested subdirectory to visually verify the fix.
* Added the corresponding HTML test file in
`Resources/Raw/foo/bar/baz/test.html` to serve as the content for the
test.
* Introduced a UITest `Issue23315` that checks if the WebView
successfully loads the file from the subdirectory and verifies the
result with a screenshot.

Validated the behaviour in the following platforms

- [x] Android
- [ ] Windows
- [x] iOS
- [x] Mac


### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #23315

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->

### Output
| Before| After|
|--|--|
| <video
src="https://github.com/user-attachments/assets/70ca7082-d50e-44e3-a6d3-c2f84e40317c">
| <video
src="https://github.com/user-attachments/assets/2cbf6baa-6da6-444e-983f-76cd922f9e28">
|

---------
PureWeen pushed a commit that referenced this pull request Jul 7, 2026
<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Description of Change

<!-- Enter description of the fix in this section -->
This pull request addresses an issue where the WebView on iOS and macOS
was unable to load files from subdirectories. The changes ensure that
files located in nested directories can be accessed and displayed
correctly in the WebView. The update includes both the necessary code
fixes and new tests to verify the behavior.

### WebView file loading improvements

* Updated the `LoadFile` method in both `WebViewHandler.iOS.cs` and
`MauiWKWebView.cs` to correctly handle file paths with subdirectories by
using the appropriate `NSBundle.GetUrlForResource` overload, ensuring
files in nested directories are found and loaded.
[[1]](diffhunk://#diff-b752aea5c6f8159ab0eea93a14b8b0fb0653d3fb30daaed38df5653bcd2f2bdcR513-R520)
[[2]](diffhunk://#diff-c0e04ad305434c245715d87f41af80af7482f37d7e8413fdeaffcad220c8e2dbR189-R196)

### New test coverage

* Added a new test case page `Issue23315` that attempts to load an HTML
file from a nested subdirectory to visually verify the fix.
* Added the corresponding HTML test file in
`Resources/Raw/foo/bar/baz/test.html` to serve as the content for the
test.
* Introduced a UITest `Issue23315` that checks if the WebView
successfully loads the file from the subdirectory and verifies the
result with a screenshot.

Validated the behaviour in the following platforms

- [x] Android
- [ ] Windows
- [x] iOS
- [x] Mac


### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #23315

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->

### Output
| Before| After|
|--|--|
| <video
src="https://github.com/user-attachments/assets/70ca7082-d50e-44e3-a6d3-c2f84e40317c">
| <video
src="https://github.com/user-attachments/assets/2cbf6baa-6da6-444e-983f-76cd922f9e28">
|

---------
PureWeen pushed a commit that referenced this pull request Jul 7, 2026
<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Description of Change

<!-- Enter description of the fix in this section -->
This pull request addresses an issue where the WebView on iOS and macOS
was unable to load files from subdirectories. The changes ensure that
files located in nested directories can be accessed and displayed
correctly in the WebView. The update includes both the necessary code
fixes and new tests to verify the behavior.

### WebView file loading improvements

* Updated the `LoadFile` method in both `WebViewHandler.iOS.cs` and
`MauiWKWebView.cs` to correctly handle file paths with subdirectories by
using the appropriate `NSBundle.GetUrlForResource` overload, ensuring
files in nested directories are found and loaded.
[[1]](diffhunk://#diff-b752aea5c6f8159ab0eea93a14b8b0fb0653d3fb30daaed38df5653bcd2f2bdcR513-R520)
[[2]](diffhunk://#diff-c0e04ad305434c245715d87f41af80af7482f37d7e8413fdeaffcad220c8e2dbR189-R196)

### New test coverage

* Added a new test case page `Issue23315` that attempts to load an HTML
file from a nested subdirectory to visually verify the fix.
* Added the corresponding HTML test file in
`Resources/Raw/foo/bar/baz/test.html` to serve as the content for the
test.
* Introduced a UITest `Issue23315` that checks if the WebView
successfully loads the file from the subdirectory and verifies the
result with a screenshot.

Validated the behaviour in the following platforms

- [x] Android
- [ ] Windows
- [x] iOS
- [x] Mac


### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #23315

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->

### Output
| Before| After|
|--|--|
| <video
src="https://github.com/user-attachments/assets/70ca7082-d50e-44e3-a6d3-c2f84e40317c">
| <video
src="https://github.com/user-attachments/assets/2cbf6baa-6da6-444e-983f-76cd922f9e28">
|

---------
kubaflo pushed a commit that referenced this pull request Jul 10, 2026
<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Description of Change

<!-- Enter description of the fix in this section -->
This pull request addresses an issue where the WebView on iOS and macOS
was unable to load files from subdirectories. The changes ensure that
files located in nested directories can be accessed and displayed
correctly in the WebView. The update includes both the necessary code
fixes and new tests to verify the behavior.

### WebView file loading improvements

* Updated the `LoadFile` method in both `WebViewHandler.iOS.cs` and
`MauiWKWebView.cs` to correctly handle file paths with subdirectories by
using the appropriate `NSBundle.GetUrlForResource` overload, ensuring
files in nested directories are found and loaded.
[[1]](diffhunk://#diff-b752aea5c6f8159ab0eea93a14b8b0fb0653d3fb30daaed38df5653bcd2f2bdcR513-R520)
[[2]](diffhunk://#diff-c0e04ad305434c245715d87f41af80af7482f37d7e8413fdeaffcad220c8e2dbR189-R196)

### New test coverage

* Added a new test case page `Issue23315` that attempts to load an HTML
file from a nested subdirectory to visually verify the fix.
* Added the corresponding HTML test file in
`Resources/Raw/foo/bar/baz/test.html` to serve as the content for the
test.
* Introduced a UITest `Issue23315` that checks if the WebView
successfully loads the file from the subdirectory and verifies the
result with a screenshot.

Validated the behaviour in the following platforms

- [x] Android
- [ ] Windows
- [x] iOS
- [x] Mac


### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #23315

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->

### Output
| Before| After|
|--|--|
| <video
src="https://github.com/user-attachments/assets/70ca7082-d50e-44e3-a6d3-c2f84e40317c">
| <video
src="https://github.com/user-attachments/assets/2cbf6baa-6da6-444e-983f-76cd922f9e28">
|

---------
kubaflo pushed a commit that referenced this pull request Jul 15, 2026
<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Description of Change

<!-- Enter description of the fix in this section -->
This pull request addresses an issue where the WebView on iOS and macOS
was unable to load files from subdirectories. The changes ensure that
files located in nested directories can be accessed and displayed
correctly in the WebView. The update includes both the necessary code
fixes and new tests to verify the behavior.

### WebView file loading improvements

* Updated the `LoadFile` method in both `WebViewHandler.iOS.cs` and
`MauiWKWebView.cs` to correctly handle file paths with subdirectories by
using the appropriate `NSBundle.GetUrlForResource` overload, ensuring
files in nested directories are found and loaded.
[[1]](diffhunk://#diff-b752aea5c6f8159ab0eea93a14b8b0fb0653d3fb30daaed38df5653bcd2f2bdcR513-R520)
[[2]](diffhunk://#diff-c0e04ad305434c245715d87f41af80af7482f37d7e8413fdeaffcad220c8e2dbR189-R196)

### New test coverage

* Added a new test case page `Issue23315` that attempts to load an HTML
file from a nested subdirectory to visually verify the fix.
* Added the corresponding HTML test file in
`Resources/Raw/foo/bar/baz/test.html` to serve as the content for the
test.
* Introduced a UITest `Issue23315` that checks if the WebView
successfully loads the file from the subdirectory and verifies the
result with a screenshot.

Validated the behaviour in the following platforms

- [x] Android
- [ ] Windows
- [x] iOS
- [x] Mac


### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #23315

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->

### Output
| Before| After|
|--|--|
| <video
src="https://github.com/user-attachments/assets/70ca7082-d50e-44e3-a6d3-c2f84e40317c">
| <video
src="https://github.com/user-attachments/assets/2cbf6baa-6da6-444e-983f-76cd922f9e28">
|

---------
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 19, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration s/agent-fix-win AI found a better alternative fix than the PR s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LoadFile in src/Core/src/Platform/iOS/MauiWKWebView.cs ignore directories.

10 participants