Skip to content

Calling method on Bound C# object throws NullReferenceException in unmanaged code #1611

@maynardflies

Description

@maynardflies
  • What steps will reproduce the problem?
  1. Create browser in code
  2. Bind object using browser.RegisterJsObject
  3. add browser to a WPF control and let it render
  4. Attempt to call a method on the object
  • What is the expected output? What do you see instead?
    Expected output would be nothing, as the method in question is a void type. I get the following error instead

salesbookBridge.invokeBloombergCommand("","","") < -- Invocation call, in DevTools (same thing happens when using JSFiddle)

VM187:2 Uncaught Error: System.NullReferenceException: Object reference not set to an instance of an object.
   at CefSharp.JavascriptMethodWrapper.Execute(Object[] parameters)
   at CefSharp.JavascriptMethodHandler.Execute(JavascriptMethodHandler* , CefStringBase<CefStringTraitsUTF16>* name, CefRefPtr<CefV8Value>* object, vector<CefRefPtr<CefV8Value>\,std::allocator<CefRefPtr<CefV8Value> > >* arguments, CefRefPtr<CefV8Value>* retval, CefStringBase<CefStringTraitsUTF16>* exception)

   at CefSharp.JavascriptMethodWrapper.Execute(Object[] parameters)
   at CefSharp.JavascriptMethodHandler.Execute(JavascriptMethodHandler* , CefStringBase<CefStringTraitsUTF16>* name, CefRefPtr<CefV8Value>* object, vector<CefRefPtr<CefV8Value>\,std::allocator<CefRefPtr<CefV8Value> > >* arguments, CefRefPtr<CefV8Value>* retval, CefStringBase<CefStringTraitsUTF16>* exception)
    at Error (native)
    at <anonymous>:2:17
    at Object.InjectedScript._evaluateOn (<anonymous>:875:140)
    at Object.InjectedScript._evaluateAndWrap (<anonymous>:808:34)
    at Object.InjectedScript.evaluate (<anonymous>:664:21)

  • Are you using WinForms, WPF or OffScreen?
    WPF
  • What version of the product are you using? On what operating system? x86 or x64?
    x86 v47.0.3
    • What version are you using? Nuget? CI Nuget? build from a branch? If so which branch?
      Nuget 47.0.3
    • Win7, Win 8, Win10, etc?
      Win7

Execution doesn't come into my managed code at all. I'm using VS2012 so I can't compile from source or debug into CefSharp.WPF as compilation is not supported in 2012 anymore

There is nothing in the debug.log file at all related to this, attempting to execute the method writes nothing to the file

It's worth noting that it does appear to find the method, as changing the call to use a non-existent method name gives a different error ("not a function"). My C# code is fairly simple

var browser = new ChromiumWebBrowser();
            if (BoundObject != null)
                browser.RegisterJsObject("salesbookBridge", BoundObject);
            AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit;
            browser.FrameLoadEnd += FrameLoaded;
             BindingOperations.SetBinding(browser, ChromiumWebBrowser.AddressProperty,
                new Binding("ContainerElement.URL"));
            this.AssociatedObject.Child = browser; <- adding the browser to a Border for rendering`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions