Crashing on Dispose in WPF

Topics: User Forum
Aug 18, 2008 at 5:52 PM
Hi all-

I'm using the ScintillaNET control in a WPF window (using a WinForms host) as follows:

editor = new ScintillaNet.Scintilla();
WindowsFormsHost host = new WindowsFormsHost();
host.Child = editor;
editorFrame.Content = host;

where editorFrame is a frame in my window.

Everything seems to work fine when using the control. The problem comes when the window is closed. It basically seems like the control is getting disposed of twice, and on the second time it can't get it's handle. The exception is "Cannot access a disposed object. Object name: 'Scintilla'." and the last debuggable chunk of code is here (in Scintilla.cs, caps comment added by me)

// wi11811 2008-07-28 Chris Rickard
// Since we eat the destroy message in WndProc
// we have to manually let Scintilla know to
// clean up its resources.
Message destroyMessage = new Message();
destroyMessage.Msg = NativeMethods.WM_DESTROY;
destroyMessage.HWnd = Handle; // <----------EXCEPTION HERE
base.DefWndProc(ref destroyMessage);

Does anyone have any experience using the control with WPF, or with this exception in general?

Thanks.

-Andy
Coordinator
Aug 18, 2008 at 6:20 PM
This problem isn't specific to WPF, I've had others report it who are using Windows Forms. I don't have a full fix for it yet but I do have a workaround that I put in. Download the latest off the code tab. Changeset 36662 has the fix.
Aug 19, 2008 at 3:26 PM
Chris-

Thanks for the quick response. Unfortunately, the fix didn't seem to work for me. I'm assuming that the if (!DesignMode) was the workaround, but DesignMode evaluates to false for me. I'm not a winforms expert so I'm not exactly sure when DesignMode is supposed to be true, but it isn't in my case.

Perhaps I'll dig a little further and try to understand what's going on.

Thanks.

-Andy

Coordinator
Aug 19, 2008 at 9:52 PM
OK, I fixed it so that it works even in WPF. Get changeset 36876.

As an aside, do you know if there's any way to get Windows Forms controls to drop on to the designer surface in the WPF designer? I had to manually register the namespace and create the XAML element.
Aug 20, 2008 at 1:19 AM
I don't think there is. As far as I know, you have to add WinFormsHost
to the XAML and assign its child in the code. Frankly, this doesn't
upset me too much as I find the new WPF designer extremely clunky to
work with (often 5-10 seconds update time when showing a designer
tab).

On Tue, Aug 19, 2008 at 5:54 PM, ChrisRickard
<notifications@codeplex.com> wrote:
> From: ChrisRickard
>
> OK, I fixed it so that it works even in WPF. Get changeset 36876.
>
> As an aside, do you know if there's any way to get Windows Forms controls to
> drop on to the designer surface in the WPF designer? I had to manually
> register the namespace and create the XAML element.
>
> Read the full discussion online.
>
> To add a post to this discussion, reply to this email
> ([email removed])
>
> To start a new discussion for this project, email
> [email removed]
>
> You are receiving this email because you subscribed to this discussion on
> CodePlex. You can unsubscribe on codePlex.com.
>
> Please note: Images and attachments will be removed from emails. Any posts
> to this discussion will also be available online at codeplex.com
Aug 25, 2008 at 7:51 PM
Yep, that worked. Thanks, Chris.

On Tue, Aug 19, 2008 at 5:54 PM, ChrisRickard
<notifications@codeplex.com> wrote:
> From: ChrisRickard
>
> OK, I fixed it so that it works even in WPF. Get changeset 36876.
>
> As an aside, do you know if there's any way to get Windows Forms controls to
> drop on to the designer surface in the WPF designer? I had to manually
> register the namespace and create the XAML element.
>
> Read the full discussion online.
>
> To add a post to this discussion, reply to this email
> ([email removed])
>
> To start a new discussion for this project, email
> [email removed]
>
> You are receiving this email because you subscribed to this discussion on
> CodePlex. You can unsubscribe on codePlex.com.
>
> Please note: Images and attachments will be removed from emails. Any posts
> to this discussion will also be available online at codeplex.com
Dec 11, 2008 at 8:13 AM
Hi, guys.
I'm sorry I do not know where to get the changeset 36876.
I get the newest source code and compile (there is an error in the file, missing a "'"), but still can not get it to work.
Please help me, my email is isml_smile@hotmail.com
Thanks in advance.