Ian Lundberg
Ian Lundberg

Reputation: 1883

c# exception error when trying to retrieve url from webbrowser

The current code I am using is

        WebBrowser browser = new WebBrowser();
        browser.Url = new Uri("http://www.youtube.com/user/RayWilliamJohnson");
        label1.Text = browser.Url.ToString();

but it is giving me a 'Object reference not set to an instance of an object.' on the label1.Text = browser.Url.ToString(); line. I don't know why it is doing this or how I can fix this and it is getting on my nerves so any help will be appreciated. Thanks in advance

Upvotes: 0

Views: 136

Answers (1)

Jonathon Reinhart
Jonathon Reinhart

Reputation: 137438

When the debugger breaks for the exception, you can:

  • hover over the variables in the editor, or
  • look in the "Locals" debug window

to see what their values are. You should be able to easily see what is null. Then work your way up the call chain, and see where it was supposed to be initialized.

enter image description here

This is straightforward debugging that you will need to learn to do if you want to be a productive developer.

Upvotes: 1

Related Questions