467,927 Members | 1,838 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,927 developers. It's quick & easy.

System.NullReferenceException at SetClientSite / IOleObject


I want to create a WebBrowser Control at runtime. So i ported the "at
start creation" of the Control to a new routine.

Everything works fine, but i implement the BeforeNavigateFix and a own
Content Menu. For this i need this lines:
public void create_new_browser()

AxSHDocVw.AxWebBrowser AxWebBrowser1 = new AxSHDocVw.AxWebBrowser();

// Here is the code for adding the control to the form
// ...
// ...

object obj = AxWebBrowser1.GetOcx();

IOleObject oc = obj as IOleObject;

oc.SetClientSite(this); // System.NullReferenceException

// Fix for OnBeforeNavigate .Net 1.0

ie_events = (SHDocVw.WebBrowserClass) Marshal.CreateWrapperOfType
(AxWebBrowser1.GetOcx(), typeof(SHDocVw.WebBrowserClass));

SHDocVw.DWebBrowserEvents_BeforeNavigateEventHandl er BeforeNavigateE =
new SHDocVw.DWebBrowserEvents_BeforeNavigateEventHandl er

ie_events.BeforeNavigate +=

If i Comment the both lines with // System.NullRefernceException it
runs, but with no BeforeNavigate Event, and not with the content menu -
which worked fine before creating it at runtime.

I tried several things, but running out of ideas and found nothing with
google :(

All it throws out is a System.NullReferenceException and that the object
ist not bound to the instance.

Maybe someone has done this before or can me give some hints.

Thanks for your Help

Nov 15 '05 #1
  • viewed: 2431

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Terrence | last post: by
1 post views Thread by msnews.microsoft.com | last post: by
3 posts views Thread by Alex J. | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.