none
WPF/C# .NET 3.5: Assembly using Imaging.Interop crashes on second load RRS feed

  • Question

  • I am using a sort of modular plugin system to load different user interfaces, which was working fine until I tried using an ActiveX control inside of one of the plugins (via a WindowsFormsHost) Everything in my project is .NET 3.5. The error occurs the second time the specific module is loaded...

    After enabling unmanaged code debugging and getting the symbols I was able to get: "STATUS_STACK_BUFFER_OVERRUN" (Before that it would just lock up the IDE)

    The offending call:

    System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap( hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());

    I've tried everything and it just doesn't want to run with that code in it, but only on the second instance of that assembly.

    When I "unload" (i know you can't completely unload an assembly) I dispose everything and kill all threads.

    The ActiveX control loads fine the second iteration, and I can see (via a watch) everything inside of the control fine, but I need the interop to render bitmaps from the AxHost into a compatible Image / BitmapSource / WritableBitmap.

    All of the other code works and has worked fine, when I comment out the Imaging interop, everything loads and unloads... but I need the images =) Has anyone here experienced anything like this before?

    I'm no "expert" -- but I've been at it for a few days and it's driving me crazy!

    Sunday, May 9, 2010 5:40 AM

Answers

  • So you are loading a native code into your plugin host. It works fine, but when you unload it and load it again, it will crash eventually. Is that correct summary?
    If yes, then I would focus on the native (ActiveX) component: Does it support unloading at all? Did it by any chance corrupt memory when unloading? Did you really unload it correctly? (for example aren't there any callbacks registered in other components)

    The symptoms you describe (locked IDE, buffer overrun, weird crashes that differ depending on what you do next) ... that all points to the fact that either your interop with native component or your native component itself somehow corrupts random memory. That usually leads to some kind of crash or hang eventually.

    -Karel

    • Marked as answer by SamAgain Friday, May 14, 2010 5:52 AM
    Sunday, May 9, 2010 10:19 PM
    Moderator

All replies

  • Also, seems to happen when I try to replace that offending code with a WritableBitmap not using interop :/

     

    Sunday, May 9, 2010 5:52 AM
  • Update, it happens even when I try to create a bitmapsource elsewhere in the application (after loading the module), outside of the assembly. So, whatever is, is affecting the entire application and any assemblies loaded.
    Sunday, May 9, 2010 2:27 PM
  • So you are loading a native code into your plugin host. It works fine, but when you unload it and load it again, it will crash eventually. Is that correct summary?
    If yes, then I would focus on the native (ActiveX) component: Does it support unloading at all? Did it by any chance corrupt memory when unloading? Did you really unload it correctly? (for example aren't there any callbacks registered in other components)

    The symptoms you describe (locked IDE, buffer overrun, weird crashes that differ depending on what you do next) ... that all points to the fact that either your interop with native component or your native component itself somehow corrupts random memory. That usually leads to some kind of crash or hang eventually.

    -Karel

    • Marked as answer by SamAgain Friday, May 14, 2010 5:52 AM
    Sunday, May 9, 2010 10:19 PM
    Moderator
  • We temporarily mark a reply, please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as Answer" if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    Please mark the right answer at right time.
    Thanks,
    Sam
    Friday, May 14, 2010 5:52 AM