Skip to content

Use random user data folder to prevent error 0x8007139F "Expecting object to be local"#4

Draft
mrautio wants to merge 3 commits intopandrr:mainfrom
mrautio:feature/random-user-data-directory
Draft

Use random user data folder to prevent error 0x8007139F "Expecting object to be local"#4
mrautio wants to merge 3 commits intopandrr:mainfrom
mrautio:feature/random-user-data-directory

Conversation

@mrautio
Copy link
Collaborator

@mrautio mrautio commented Apr 27, 2025

If there are unrelated Windows programs that utilize WebView2, starting of demo may result in System.Runtime.InteropServices.COMException (0x8007139F): Expecting object to be local error since WebDemo.exe tries to use pre-existing WebView2 process. This Pull Request places WebView2 user data folder under a random temp folder preventing the issue from occurring.

WebView2 process describes shared user data folder behavior: https://learn.microsoft.com/en-us/microsoft-edge/webview2/concepts/process-model?tabs=csharp

image

@mrautio mrautio force-pushed the feature/random-user-data-directory branch from 62e7ff7 to 28fec48 Compare July 27, 2025 09:52
@mrautio mrautio requested a review from Copilot July 27, 2025 09:54
Copy link

Copilot AI left a comment

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 addresses a COM exception (0x8007139F "Expecting object to be local") that occurs when multiple Windows programs utilize WebView2 by isolating the WebView2 user data folder. The solution creates a unique temporary folder for each instance and adds proper cleanup on application exit.

  • Create unique user data folder using random filename to prevent conflicts
  • Add window closing event handler to ensure proper cleanup
  • Implement cleanup logic to remove temporary folder and terminate WebView2 process

@mrautio mrautio marked this pull request as draft July 27, 2025 10:08
@mrautio mrautio force-pushed the feature/random-user-data-directory branch from 28fec48 to fe64c3f Compare July 27, 2025 10:13
mrautio added 3 commits March 8, 2026 10:33
WebView2 process is shared per associated user data folder. if there is another program using same user data folder then it's possible that demo throws exception:  and fails to run.
@mrautio mrautio force-pushed the feature/random-user-data-directory branch from fe64c3f to fdd64f2 Compare March 8, 2026 08:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants