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

[Problem/Bug]: Opening a connection to an Access database breaks the WebView2 #4583

Closed
AFatNiBBa opened this issue May 23, 2024 · 8 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@AFatNiBBa
Copy link

What happened?

I'm trying to make a custom window for popups, but if I open a connection to an Access database and THEN open a popup window, WebView2.EnsureCoreWebView2Async() throws a COMException saying:

System.Reflection.TargetInvocationException: Eccezione generata dalla destinazione di una chiamata. ---> System.Runtime.InteropServices.COMException: Il gruppo o la risorsa non si trova nello stato appropriato per eseguire l'operazione richiesta. (Eccezione da HRESULT: 0x8007139F)
   in System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
   in Microsoft.Web.WebView2.Core.CoreWebView2Environment.<CreateCoreWebView2ControllerAsync>d__98.MoveNext()
--- Fine traccia dello stack da posizione precedente dove è stata generata l'eccezione ---
   in System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   in System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   in System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   in Microsoft.Web.WebView2.WinForms.WebView2.<InitCoreWebView2Async>d__25.MoveNext()
--- Fine traccia dello stack da posizione precedente dove è stata generata l'eccezione ---
   in System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   in System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   in System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   in TestOleDb.Form1.<<Init>b__1_0>d.MoveNext() in C:\Users\Sean Alunni\Downloads\TestOleDb\TestOleDb\Form1.cs:riga 41
--- Fine traccia dello stack da posizione precedente dove è stata generata l'eccezione ---
   in System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c.<ThrowAsync>b__6_0(Object state)
   --- Fine della traccia dello stack dell'eccezione interna ---
   in System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   in System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   in System.Delegate.DynamicInvokeImpl(Object[] args)
   in System.Windows.Forms.Control.InvokeMarshaledCallbackDo(ThreadMethodEntry tme)
   in System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(Object obj)
   in System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   in System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   in System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   in System.Windows.Forms.Control.InvokeMarshaledCallback(ThreadMethodEntry tme)
   in System.Windows.Forms.Control.InvokeMarshaledCallbacks()
   in System.Windows.Forms.Control.WndProc(Message& m)
   in System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   in System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   in System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   in System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   in System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   in System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   in System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   in System.Windows.Forms.Application.Run(Form mainForm)
   in TestOleDb.Program.Main() in C:\Users\Sean Alunni\Downloads\TestOleDb\TestOleDb\Program.cs:riga 19

The text is in Italian because it's my system language

Importance

Important. My app's user experience is significantly compromised.

Runtime Channel

Stable release (WebView2 Runtime)

Runtime Version

124.0.2478.97

SDK Version

1.0.2478.35

Framework

Winforms

Operating System

Windows 11

OS Version

22631.3593

Repro steps

  1. Download this zipped solution: TestOleDb.zip
  2. Run the application
  3. Click the "Break" button and THEN the "Popup" one

If you click only the "Popup" button it will work

Repros in Edge Browser

No, issue does not reproduce in the corresponding Edge version

Regression

Don't know

Last working version (if regression)

No response

@AFatNiBBa AFatNiBBa added the bug Something isn't working label May 23, 2024
@JosephJin0815
Copy link
Contributor

It works fine for me. No matter Click "break" first or not. And "connection to an Access database" is irrelative.
Here's a thread with regard to the System.Runtime.InteropServices.COMException 0x8007139F error.

@AFatNiBBa
Copy link
Author

Try changing the button handler from this

private void cmdBreak_Click(object sender, EventArgs e)
{
    var path = $"{Application.StartupPath}/TestOleDb.accdb";
    using var connection = new OleDbConnection($"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={path}"); // The database doesn't even need to exist
    try { connection.Open(); }
    catch { }
}

to this

private void cmdBreak_Click(object sender, EventArgs e)
{
    var path = $"{Application.StartupPath}/TestOleDb.accdb";
    using var connection = new OleDbConnection($"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={path}"); // The database doesn't even need to exist
    try { connection.Open(); }
    catch (OleDbException) { }
}

The handler had a catch that was meant to handle the case in which the database didn't exist (Which still breaks my custom popup).
I suspect that you don't have the "Microsoft.ACE.OLEDB.12.0" provider installed and that catch was handling that exception too.
Now the program should crash if you don't have it installed.
I've tried "Microsoft.ACE.OLEDB.16.0" and "Microsoft.JET.OLEDB.4.0" too, but they don't seem to break the webview

@JosephJin0815
Copy link
Contributor

JosephJin0815 commented Jun 3, 2024

Tried catch the exception. Click Break -> click Continue to ignore the error -> Click Popup -> New form with google page loaded.
If you take an ETW trace of the repro, we could know more about that failed.
How to take ETW trace: https://github.com/MicrosoftEdge/WebView2Feedback/blob/main/diagnostics/etw.md

@AFatNiBBa
Copy link
Author

AFatNiBBa commented Jun 4, 2024

I started the trace, clicked "Break", clicked "Popup" and then stopped the trace.
To minimize interferences I ran the .exe directly without Visual Studio, I think it is worth to notice that this time the program didn't immediately crash after the error, my CUSTOM popup window showed up without anything inside and the STANDARD popup window showed up with the requested page

ETW traces can contain sensitive information, if you're concerned with sharing one publicly in a GitHub issue, you can ask the WV2 developer you're working with for an email address to send to them privately

This would be preferred

@JosephJin0815
Copy link
Contributor

You can send the trace to wangsongjin@microsoft.com

@JosephJin0815
Copy link
Contributor

@AFatNiBBa From your traces, the WebView2.EnsureCoreWebView2Async(wv.CoreWebView2.Environment) failed for incompatible DPI awareness. The new popup window has different DPI value compared with existing wv.CoreWebView2 you've created. While I have no clue why open a connection to access database could cause this mismatch on your testing environment.

Recommend you to check #2495, #4391, #1464

@JosephJin0815
Copy link
Contributor

More Info from the trace:
Existing: DPI_AWARENESS_UNAWARE
New: DPI_AWARENESS_SYSTEM_AWARE
image
DPI_AWARENESS enumeration (windef.h)

@AFatNiBBa
Copy link
Author

We managed to fix the issue in an unforgivable manner by just forcing a connection BEFORE the first WebView2 was created.
We haven't found a way to prevent the change in DPI awareness, but now it doesn't happen during the life cycle of the WebView2 at least

try
{
  using (var conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0"))
    conn.Open();
}
catch { }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants