Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SendWebMessage from WindowCreated handler raises a System.AccessViolationException #87

Open
albertospelta opened this issue Jan 29, 2022 · 1 comment
Labels
All OS enhancement New feature or request help wanted Extra attention is needed

Comments

@albertospelta
Copy link

albertospelta commented Jan 29, 2022

Hi,
I've come across this System.AccessViolationException error after trying to send a web message from the WindowCreated handler.

After digging into the issue, I realized that this stems from the fact that the creation of the Photino.Native <ICoreWebView2> _webviewWindow instance is deferred until the message loop is started. Probably due to the Photino::AttachWebView() CreateCoreWebView2EnvironmentWithOptions callback.

Here is the native error

// Exception thrown: read access violation.
this->_webviewWindow.**m_ptr** was nullptr.

To reproduce:

var window = new PhotinoWindow
{
    StartUrl = "wwwroot/main.html",
    WindowCreatedHandler = (sender, args) => (sender as PhotinoWindow).SendWebMessage("test message"),
};
window.WaitForClose();

Expected behavior
I would expect all methods to be available in the WindowCreated event handler since the window has already been created

Additional context

  • .NET 5, VisualStudio 2022
  • Photino.NET package version 2.1.11
  • Windows 11 version 21H2 build 22000

Great work on this framework!
Thanks,
Alberto

@ottodobretsberger
Copy link
Contributor

Thank you for raising this issue. The way this would need to be addressed is to implement a callback event that notifies upon successful creation of the browser, after which the SendWebMessage will be available.
If time permits we will look into that as well, unless the community would like to pick up this task.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
All OS enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants