Welcome Guest Search | Active Topics | Sign In | Register

This WebView either has already been destroyed or is being destroyed. Options
Mohammed Ayyub
Posted: Friday, February 17, 2023 7:31:46 AM
Rank: Member
Groups: Member

Joined: 2/8/2023
Posts: 14
Hi Team,

I am facing the below issue while loading the url:

Code: C#
public class Browser : EO.WinForm.WebControl

public Browser()
            : base()
        {
             if (this.WebView == null)
            {
                this.WebView = new WebView();
            }

            this.WebView.ObjectForScripting = new ExternalHost(this);

            this.WebView.BeforeDownload += WebView_BeforeDownload;
            this.WebView.DownloadCompleted += WebView_DownloadCompleted;
            this.WebView.NewWindow += WebView_NewWindow;// OnNewWindow;// WebView_NewWindow;
            this.WebView.NeedCredentials += WebView_NeedCredentials;
            this.WebView.CertificateError += WebView_CertificateError;
            this.WebView.LoadCompleted += WebView_LoadCompleted;
            this.WebView.Disposed += WebView_Disposed;
            EO.Base.Runtime.Exception += Runtime_Exception;
            this.ShowProgressBar();
            WebView.ShowDevTools(Handle);
            EO.WebBrowser.WebView.ShowDebugUI();

            int GiveMeInfo = CommandIds.RegisterUserCommand("GiveMeInfo");
            this.WebView.Shortcuts = new Shortcut[]
                {
                 new Shortcut(1, KeyCode.F5, true, true, false),
                new Shortcut(2, KeyCode.F12, true, true, false),
                new Shortcut(3, KeyCode.F4, true, true, false),
                };

            this.WebView.Command += WebView_Command;
        }

void Navigate()
{
//[color=red]Here it is throwing Exception[/color]
this.WebView.Url = SecuredURL;
}


System.Exception
HResult=0x80131500
Message=This WebView either has already been destroyed or is being destroyed.
Source=EO.Base
StackTrace:
at EO.Base.Runtime.yfcz(Object lsy, Exception lsz, Boolean lta)
at EO.WebBrowser.WebView.rqlh(Exception fp, Boolean fq)
at EO.WebBrowser.WebView.rqhk(Boolean ad)
at EO.WebBrowser.WebView.LoadUrl(String url, Boolean skipCache)
at EO.WebBrowser.WebView.set_Url(String value)
at ExtendedWebBrowser.Browser.Navigate() in M:\SPDev\\EOWebBrowser\Browser.cs:line 958
at WinForms.aaWorkflowAssociation.Navigate() in M:\SPDev\Extensions\WinForms\aaWorkflowAssociation.cs:line 144
at IDEExtension.A2Object.aaWorkflowsTab.ShowAssociationPage(String objectName, String eventName, Boolean readOnly, Boolean inherited) in M:\SPDev\Extensions\IDEExtension\A2Object\aaWorkflowsTab.cs:line 1676

This exception was originally thrown at this call stack:
EO.Base.Runtime.yfcz(object, System.Exception, bool)
EO.WebBrowser.WebView.rqlh(System.Exception, bool)
EO.WebBrowser.WebView.rqhk(bool)
EO.WebBrowser.WebView.LoadUrl(string, bool)
EO.WebBrowser.WebView.Url.set(string)
ExtendedWebBrowser.Browser.Navigate() in Browser.cs
WinForms.aaWorkflowAssociation.Navigate() in aaWorkflowAssociation.cs
IDEExtension.A2Object.aaWorkflowsTab.ShowAssociationPage(string, string, bool, bool) in aaWorkflowsTab.cs

eo_support
Posted: Friday, February 17, 2023 11:51:49 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,086
Hi,

Did you call the WebView's Create method? Your code did not show when the WebView's Create method is called.

If you are not sure how to call the WebView's Create method, you can use EO.WinForm.WebBrowser control. The basic code will be like this:

Code: C#
private EO.WinForm.WebBrowser webBrowser;

//Initialize the WebBrowser, replace location and size
//with desired value, you can also use Dock property
//to fill the parent control with the WebBrowser
webBrowser = new EO.WinForm.WebBrowser();
webBrowser.Location = location;
webBrowser.Size = size;

//Link WebBrowser and your WebView
webBrowser.WebView = this.WebView;

//Add the WebBrowser control to your control
this.Controls.Add(webBrowser);


As you can see the WebBrowser control serves a bridge between your Windows.Forms control and the WebView. It will automatically handle creation and destruction the WebView.

Hope this helps.

Thanks
Mohammed Ayyub
Posted: Monday, February 20, 2023 1:22:01 AM
Rank: Member
Groups: Member

Joined: 2/8/2023
Posts: 14
Hi,

Thanks for your response.
I found out the the actual issue, but not sure why it is throwing the below exception:

Object 'MainXXX.SubYYY.IDEExtension.A2Object.aaParamsClientObject' of type 'MainXXX.SubYYY.IDEExtension.A2Object.aaParamsClientObject' can not be passed to JavaScript code.

I am try to use JavaScript Extension "ObjectForScripting"

Code: C#
this.WebView.ObjectForScripting = new ExternalHost(this);

    internal class ExternalHost
    {
        Browser browser;
        internal ExternalHost(Browser browserObject)
        {
            browser = browserObject;
        }

        public object Service(string serviceName)
        {
            object service = null;
            _Services.TryGetValue(serviceName, out service);
            return service;
        }

        public void Hello(string s)
        {
            MessageBox.Show("Hello From Script:" + s);
        }
    }

    [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
    [System.Runtime.InteropServices.ComVisibleAttribute(true)]
    public class aaParamsClientObject
    {
        string _EventName;
        public string EventName
        {
            get { return _EventName; }
            set { _EventName = value; }
        }

        private string GetXmlString()
        {
          //Some logic
         }
    }


JavaScript code:
Code: JavaScript
// This line works
window.external.Hello('Hello from JavaScript!');
// The below two lines fails. I have multiple objects and I need invoke the different methods from different objects, hence I am storing those object in Service object and from that I want to call it.
// This worked in IE WebBrowser control, but here it is failing.
window.external.Service('aaParamsClientObject').EventName
window.external.Service('aaParamsClientObject').GetXmlString()


eo_support
Posted: Monday, February 20, 2023 12:36:12 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,086
Hi,

For performance reason, our ObjectForScripting implementation does not allow returning/passing complex types. For example, the following method is valid because argument "s" is a simple type:

Code: C#
public void Hello(string a)
{
    MessageBox.Show("Hello From Script:" + a);
}


The following method is NOT valid because argument a is a complex type:
Code: C#
public void Hello(aaParamsClientObject a)
{
    MessageBox.Show("Hello From Script:" + a);
}


The above method will cause the exception you are seeing. In your case, since you are returning an object of type aaParamsClientObject from your Service method, it will violate the same restriction. To resolve this issue, you must change your interface to only return simple types. For example, instead of relying on code like this:

Code: JavaScript
window.external.Service('aaParamsClientObject').GetXmlString()


You can add a function like this on your ExternalHost class:

Code: C#
//Service method should be private because it should not be called
//directly from the JavaScript side
private object Service(string serviceName)
{
    object service = null;
    _Services.TryGetValue(serviceName, out service);
    return service;
}

//This is the public method for the JavaScript side to call and it
//returns only simple object (string)
public function Get_aaParamsClientObject_XmlString()
{
    return Service("aaParamsClientObject").GetXmlString();
}


You would then change your JavaScript code to:
Code: JavaScript
window.external.Get_aaParamsClientObject_XmlString();


Hope this helps.

Thanks!
Mohammed Ayyub
Posted: Tuesday, February 21, 2023 1:13:20 AM
Rank: Member
Groups: Member

Joined: 2/8/2023
Posts: 14
Hi,

Thanks for the response.

The below code does not work/compile as the method "Service" return type is "object" and it does not have GetXmlString method.
Code: C#
public function Get_aaParamsClientObject_XmlString()
{
    return Service("aaParamsClientObject").GetXmlString();
}

We can type cast it and call the respective property/method, but the class/object is part of some other component, and that component will not be available in the machine where it is called.

Hence this approach will not work for us, if you could let us know some other approach that will be helpful.
Thanks.
eo_support
Posted: Tuesday, February 21, 2023 9:47:37 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,086
Mohammed Ayyub wrote:

We can type cast it and call the respective property/method, but the class/object is part of some other component, and that component will not be available in the machine where it is called.


You will have to work out such problem yourself. The code we provided is not meant for you to copy and paste --- it is meant to explain to you how our product works. In this case the key point we are trying to explain to you is you CAN NOT pass/return complex object. So you will have to change your code to avoid doing so. Exactly how to achieve that will be up to you.


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.