Search code examples
c#.netwpfchromium-embeddedcefsharp

CEF Sharp causing an Object Disposed Exception


While I understand what an object disposed exception is, I don't quite know why it is occurring immediately after the object is instantiated. Below is my code:

var cookiemanager = Cef.GetGlobalCookieManager();
cookiemanager.SetCookieAsync(Domain, Cookie);

The error is occurring on the second line when I attempt to call the SetCookieAsync function stating:

An exception of type 'System.ObjectDisposedException' occurred in CefSharp.Core.dll but was not handled in user code

Any help on why the object was disposed or what I can do to remedy this error would be greatly appreciated!


Solution

  • After some more tinkering I decided to look at the provided Cef examples where I found the following snippet:

    Cef.OnContextInitialized = delegate
    {
        var cookiemanager = Cef.GetGlobalCookieManager();
        cookiemanager.SetCookieAsync(Domain, Cookie);
    };
    

    Making this changed seemed to work!