ObjectDisposedException when accessing bound object on certain sites
- Dominant language
- C#
- Stars
- 10.3k
- Forks
- 2.9k
- Avg merge
- 5d 22h
- Merged PRs (30d)
- 4
Description
### 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.
Contributor guide
Research direction
Reproduce the failure in the CefSharp.WinForms.Example using the Test Hello flow and LegacyBindingEnabled set in BrowserTabUserControl.cs. Start by tracing the binding call through JavascriptMethodWrapper.cpp and JavascriptMethodHandler.cpp, while comparing the behavior with issue 4621. Done means the bound object remains callable on the affected sites and the script returns a value without ObjectDisposedException.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, csharp
- Domain
- desktop
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100