.NET

.NET

Reply
Active Contributor
Gdiael
Posts: 26
Registered: ‎06-09-2012
Message 1 of 10 (870 Views)
Accepted Solution

JavaScript and WebBrowser control error

870 Views, 9 Replies
02-15-2013 12:56 PM

I have a Form with a WebBrowser Control loaded with a html file with javascript, all the javascript functions and interaction with vb.net are working fine, but when I close the Form and open again (or go to another drawing and I try to open it there) happens a fatal error.

 

I've tried several ways and can not understand what is going wrong.
And also googled for people with a similar problem and did not find anyone.

Thanks if anyone can help me.

 

Gdiael Barros.

Hello Gdiael,

 

Can you try running the command in session context ?

 

I remember having seen an issue with Webbrowser not displaying videos when the command was run in the document context. Running it in Session context had fixed it.

 

The crash that you are observing does not sound similar, but the change is quite simple and easy to try.

 

 

[CommandMethod("WBrowserTest", CommandFlags.Modal | CommandFlags.Session)]

 

 

 

 

 

 

 

ADN Support Specialist
philippe.leefsma
Posts: 676
Registered: ‎06-02-2009
Message 2 of 10 (834 Views)

Re: JavaScript and WebBrowser control error

02-19-2013 07:14 AM in reply to: Gdiael

Hi Gdiael,

 

Can you provide a buildable sample? I will take a look then. It is unusual for AutoCAD developers to use this kind of control, so I am not sure if it is supported while running inside AutoCAD. Did you try reproducing the issue outside of AutoCAD, in a standalone exe, do you notice the same behavior?

 

Thank you.

 

Regards,

Philippe.



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

Active Contributor
Gdiael
Posts: 26
Registered: ‎06-09-2012
Message 3 of 10 (812 Views)

Re: JavaScript and WebBrowser control error

02-21-2013 05:42 AM in reply to: Gdiael

 

Thank you for the attention Philippe.

 

I did several test and I was working on my project since I made the post, and yes, I tried using a separate exe and it worked normally.
Furthermore I noticed that is not my html file that is causing the fatal error, even scripts running on it. In fact any site that I send WebBrowser Control to navigate causes the problem.

I pasted the vb.net code below.

 

I created a new Windows Form with a WebBrowser on it and a button called BtOK.

What happens is that when I call the command WBrowserTest few consecutive times (sometimes an attempt, sometimes several attempts) AutoCAD gives me a fatal error. When I try on a heavy file, occurs on the second attempt (the first always works), in a lighter files takes a few more attempts to fatal error occurs.

I also discovered that the WebBrowser is a resource-intensive control (which I do not know exactly what means, beyond what the word suggests). But Kean put this thing in his blog:

 

"A word of caution: some of these higher levels are extremely resource-intensive. Please do not attempt to play around with something like this while working on something you don't want to lose: there is always a slim chance of the application (and even the system, if you're really unlucky) being brought down when system resources become scarce."

In the end of this post: http://through-the-interface.typepad.com/through_the_interface/2008/07/turtle-fracta-1.html

 

I would greatly appreciate if you can help me even a bit.

 

Gdiael.

 

Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.Runtime
Imports System.Security.Permissions
Imports System.Runtime.InteropServices

<ComVisible(True)>
<PermissionSet(SecurityAction.InheritanceDemand, Name:="FullTrust")>
<PermissionSet(SecurityAction.Demand, Name:="FullTrust")>
Public Class WebBrowserTest

    <CommandMethod("WBrowserTest")>
    Public Sub LoadForm_command()
        Using Dialog As New WebBrowserTest
            Application.ShowModalDialog(Dialog)
            Dialog.Dispose()
        End Using
    End Sub

    Private Sub WebBrowserTest_load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        WebBrowser1.Navigate("www.google.com")
    End Sub

    Private Sub BtOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtOK.Click
        Me.Close()
    End Sub

End Class

 

Moderator
Alexander.Rivilis
Posts: 1,458
Registered: ‎04-09-2008
Message 4 of 10 (808 Views)

Re: JavaScript and WebBrowser control error

02-21-2013 06:12 AM in reply to: Gdiael

Are you sure that you need to call Dialog.Dispose () inside the Using? I.e. it is looking like you call Dialog.Dispose () twice.


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Active Contributor
Gdiael
Posts: 26
Registered: ‎06-09-2012
Message 5 of 10 (803 Views)

Re: JavaScript and WebBrowser control error

02-21-2013 06:30 AM in reply to: Alexander.Rivilis

Sorry, I know it's not necessary, I put during testing to see if it made any difference and I forgot to remove. But surely this is not what is causing the fatal error.

 

Gdiael

Distinguished Mentor
gasty1001
Posts: 582
Registered: ‎04-11-2010
Message 6 of 10 (793 Views)

Re: JavaScript and WebBrowser control error

02-21-2013 08:26 AM in reply to: Gdiael

Hi,

 

I can not reproduce the issue with almos exactly the same code (without the double dispose), platform: AutoCAD 2012 and 2013 both on 32 bits (Windows Server 2008 R1 SP1 for AutoCAD 2012 and W7 Ultimate for 2013) iexplorer 8 and 9, VS 2010 SP1 .NET 4.0.

Just a shot in the dark: Update all the components(hot fixes, SPs, etc) in the test system and check again.

 

Gaston Nunez

 

Active Contributor
Gdiael
Posts: 26
Registered: ‎06-09-2012
Message 7 of 10 (790 Views)

Re: JavaScript and WebBrowser control error

02-21-2013 08:39 AM in reply to: gasty1001

Thanks Gaston, but my system is up to date and AutoCAD has all the updates. Do not know if this is the case, but I'm using windows 8, which is not supported by my version of AutoCAD, yet all my other codes work smoothly, and using AutoCAD normally I never got a fatal error.

Distinguished Mentor
gasty1001
Posts: 582
Registered: ‎04-11-2010
Message 8 of 10 (787 Views)

Re: JavaScript and WebBrowser control error

02-21-2013 08:54 AM in reply to: Gdiael

Hi,

 

Later today i will try with w8 and AutoCAD 2013, I'll let you know the results.

 

Gaston Nunez

ADN Support Specialist
Balaji_Ram
Posts: 749
Registered: ‎03-21-2011
Message 9 of 10 (762 Views)

Re: JavaScript and WebBrowser control error

02-23-2013 10:14 PM in reply to: Gdiael

Hello Gdiael,

 

Can you try running the command in session context ?

 

I remember having seen an issue with Webbrowser not displaying videos when the command was run in the document context. Running it in Session context had fixed it.

 

The crash that you are observing does not sound similar, but the change is quite simple and easy to try.

 

 

[CommandMethod("WBrowserTest", CommandFlags.Modal | CommandFlags.Session)]

 

 

 

 

 

 

 



Balaji
Developer Technical Services
Autodesk Developer Network

Active Contributor
Gdiael
Posts: 26
Registered: ‎06-09-2012
Message 10 of 10 (720 Views)

Re: JavaScript and WebBrowser control error

03-03-2013 05:37 AM in reply to: Balaji_Ram

Sorry for the delay in responding, this week was quite complicated.
Thank you for the tip, it worked very well.

 

Gdiael

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.