views:

691

answers:

2

I'm having problems with SVG files loading in a .NET 2.0 WebBrowser control. If I create a new WinForms application project, drag a WebBrowser control and a button onto the Form1.cs design surface, and add a line to the button's on-click handler to set the Url property of the WebBrowser control to an SVG file, I get two IE script errors at runtime (as in, the dialog you get when there is a Javascript problem). The only line of code I'm writing is therefore:

webBrowser1.Url = new Uri(@"http://wiki.allegro.cc/pub/f/fb/Grozilla.svg");

This SVG file loads fine if I browse directly to the link with IE; the errors I get via my test app are:

line 2, char 1, error: Invalid character, followed by line 1, char 1, error: Object expected

(assuming I answer yes to the prompt to 'continue running scripts on this page').

I'm using IE 7.0.5730.13, Adobe SVG Viewer 3.03 build 94, Visual Studio 2008. Can anyone replicate this? Has anyone seen it/got any idea how to fix it?

(edit: previously setting the URL in the constructor for the purposes of the example, but this raised the question of whether or not the control had finished initialising, so have changed the example to use a button - the problem still occurs. This bug originally appeared in production code so the example program I wrote was an attempt to isolate the issue and reproduce it as simply as possible.)

(edit 2: having tested on several different machines, this problems seems to be related to IE7 - run IE6, and everything works fine.)

A: 

I've found that when working with the WebBrowser, you can't make calls to navigate to a page when the control is being created.

I've gotten around this by creating a timer that fires once when the form is loaded (enable it in the constructor) and then in the event handler for the timer, call Navigate or set the Url property and it should work.

I couldn't tell you why though for the life of me.

casperOne
Thanks for the reply - I actually get the same behaviour if I set the URL in a button click handler so I don't think it's the timing that's the problem. I'll edit my question to reflect this.
A: 

Looks like adding the source website of the SVG file to my Trusted Sites list solves the problem, so it's something to do with IE security.