ObjectDisposedException when accessing bound object on certain sites
- Lingua principale
- C#
- Stelle
- 10.3k
- Fork
- 2.9k
- Merge medio
- 5g 22h
- PR unite (30g)
- 4
Descrizione
### Is there an existing issue for this?
- [x] I have searched both open/closed issues, no issue already exists.
### CefSharp Version
150
### Operating System
Windows 11
### Architecture
x64
### .Net Version
4.7.2
### Implementation
WinForms
### Reproduction Steps
1. Clone https://github.com/jsoldi/CefSharp
2. Launch CefSharp.WinForms.Example
3. Select from main menu Test -> Hello
4. Wait a few seconds and see debug console output
### Expected behavior
Script should return a value without failing
### Actual behavior
An error occurs:
```
Uncaught Error: System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'System.ServiceModel.Channels.ServiceChannel'.
Server stack trace:
at System.ServiceModel.Channels.CommunicationObject.ThrowIfDisposedOrNotOpen()
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at CefSharp.Internals.Wcf.IBrowserProcess.CallMethod(Int64 objectId, String name, Object[] parameters)
at CefSharp.BrowserSubprocess.JavascriptMethodWrapper.Execute(Object[] parameters) in C:\Users\jsold\Desktop\CefSharp\CefSharp\CefSharp.BrowserSubprocess.Core\JavascriptMethodWrapper.cpp:line 26
at CefSharp.BrowserSubprocess.JavascriptMethodHandler.Execute(JavascriptMethodHandler* , CefStringBase* name, scoped_refptr* object, vector\,std::allocator > >* arguments, scoped_refptr* retval, CefStringBase* exception) in C:\Users\jsold\Desktop\CefSharp\CefSharp\CefSharp.BrowserSubprocess.Core\JavascriptMethodHandler.cpp:line 25
@ about:blank:1:6
```
### Regression?
_No response_
### Known Workarounds
_No response_
### Does this problem also occur in the CEF Sample Application
Yes on the WinForms example. I have also had this error on headless mode but don't have replication steps.
### Other information
I'm sure this bug is related to https://github.com/cefsharp/CefSharp/issues/4621 which is marked as closed. It occurs in the exact same pages and situations in which that error occurred on previous versions. The only difference is that in the new version the error message has changed from "Request BrowserId : 1 not found it's likely the browser is already closed" to an ObjectDisposedException.
The error only seems to occur when `LegacyBindingEnabled` is true. I don't know where the proper place to set this property is in the WinForms example project so I just set it on `BrowserTabUserControl.cs`. I only made a few changes to the fork which I updated from the master CefSharp repo a few minutes ago. The changes I made are here all one commit: https://github.com/jsoldi/CefSharp/commit/55732f05daabaa66198e055f09badc6903413dd2
I haven't found any other URL in which this error occurs than the one on my test, but it seems to me that the bug was fixed for non-legacy binding but not for legacy. I need legacy binding so the object is available before the page completes loading. If I recall correctly, non-legacy binding only adds the object after the page has loaded.
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Riproducete il malfunzionamento in CefSharp.WinForms.Example usando il flusso Test Hello e con LegacyBindingEnabled impostato in BrowserTabUserControl.cs. Iniziate tracciando la chiamata di binding attraverso JavascriptMethodWrapper.cpp e JavascriptMethodHandler.cpp, confrontando al contempo il comportamento con issue 4621. Il lavoro è completato quando l'oggetto associato rimane invocabile nei siti interessati e lo script restituisce un valore senza ObjectDisposedException.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- cpp, csharp
- Ambito
- desktop
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Tranquilla
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 48/100