External component has thrown an exception

Hi,

I'm getting this error really sporadically in my Winforms app. Seems to happen when trying to display a form with a call to .ShowDialog(). It doesn't seem to happen on any particular form, just pops up now & again. I can close the application and restart it, then I can view the form without the error

The application is running in a Citrix terminal server environment, the assemblies themselves are running from a network share. Can anyone think of what would be causing this error - why is it only happening every now & then (the worst sort of errors!). One post mentions a faulty network connection to blame, but our network is pretty solid & we run a number of other applications from shares.

I've seen a few other people reporting this issue (in exactly the same scenario, winforms app running over terminal services), but with no resolution. There have been a few posts that suggest Application.EnableVisualStyles is to blame & a call to Application.DoEvents() just after calling EnableVisualStyle is the solution. However, this is not running in XP so I don't think it applies

Would appreciate any advice on this one...the exception itself is fairly ambiguous!

Thanks

Dylan



Answer this question

External component has thrown an exception

  • cherriesh

    Hi Seth,

    Thanks for the replies - thought I was alone on this one!

    Nope - I'm on exactly the same platform as you, 1.1 app running on Citrix metafram 2K. I think you're correct about the GDI stuff....I've seen a few other posts that suggest this...I might use Spy++ to try and figure out where the invalid handles are cropping up.

    As far as the stack trace goes, I set up a couple of generic handlers when my app starts...eg;

    // Unhandled exceptions for our Application Domain

    AppDomain.CurrentDomain.UnhandledException += new System.UnhandledExceptionEventHandler(AppDomain_UnhandledException);

    // Unhandled exceptions for the executing thread

    Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);

    You can then trap any unhandled exceptions that occur in these event handlers - I'm using log4Net to dump to a local error file..

    Logger.DoErrorDump(e.Exception);

    I'll post back if I have any joy!

    Cheers


  • Markku Behm

    Yeah, I got too caught up in the idea that you could do what the object model suggested you could and didn't stop and think, "wait, where does all this stuff come from and what can it actually do " Foolish me.

  • DeepScratch

    Thanks for the link, I should've checked it earlier.

    That suggests that it is yet another problem with the winforms parking window. You know, sometimes I think it would've been easier if they had've constructed winforms to expose some more of the nature of win32 windows so that it was at least obvious where problems could occur and be fixed. The parking window has been the source of hundreds of hours of grief for my company and myself.
    They could've at least said - do not create dynamic forms with custom painting routines, and try and steer clear of dynamic behaviour full stop. That way we could at least be prepared for the unexpected when trying to build a modern smart client on a mesozoic windowing framework.

    Rant over sorry.
    .NET 2.0 winforms look like they might do the trick much better.

    Anyway, we're giving up on this in the mean time, trying to get some help with it from citrix.

    I know what you mean about the custom controls not being the cuprit - ultimately I expect that the behaviour that creates the situation where the custom controls fail is from our custom flow layout panel that is built to be able to render lots of pure .NET controls on the compact framework with some semblance of speed. It does this by spoon feeding the underlying panel's controls collection from a much faster linked list. I too have been thinking that the continual addition and removal of controls involved in doing this is corrupting the window handles on Citrix.
    When I read what I am writing here from the context of somebody who has now been through the winforms war, I just laugh at my naieve assumption that I'd be able to do what it looks like the framework is capable of - that is, simple custom-drawn controls strung together in tree/table structures etc. Turns out this was a v2.0 feature eh

    Sorry, I'm a bit bitter and twisted about my winforms experiences and can't quite bring myself to sanitise my posts for the sake of the perpetrator of the crime.

  • Martin_TeroSolutions

    One more thing.
    We are having the issue in a Citrix metaframe environment on 2k3 running a .NET 1.1 app. What platform are you using It looked like there might be a generic in the stack trace above, signifying .NET 2.0. We were kinda hoping that upgrading to .NET 2.0 might be a magic bullet for this problem.

    BTW, since you're having the exception in InitialiseComponent, I would carefully remove each 3rd party or custom drawn control until you find the one that is causing the error.

    I'm also wondering how you managed to get a stack trace beyond ShowDialog - is there any fancy trick that you used here

  • Ewaite

    Im guessing it might be a problem with your objects dispose. Use a memory profiler and check whether all the objects have been disposed.
  • snavece

    Hi,

    Did anyone figure out any good work-arounds for this SEH Exception problem We are getting a similar problem that results from displaying a form in a drag&drop event and then closing the form.

    We are using a (particularly horrible) work-around involving timers to delay the display of the form until after the event has completed and I was wondering if anyone had a better solution or if any Microsoft support engineers were willing to have a look it. We have a simple and reproducible (tested on three machines) application that demonstrates the problem if anyone needs it.

    Thanks,

    Ashley Davis

    Lead Programmer

    Kuju Entertainment Ltd



  • Madhukar Bhalerao

    I feel your pain. I have a similarly horrible problem that I can't replicate.

    I found a thread early last year that I have since lost that explained some of the issues that might be causing this.

    In my project, which is encountering exactly the same problems, the problems have been caused by custom drawing and use of the CreateGraphics method on a control to do string measurement.
    We fixed the string measurement problems by centralising the functionality around a central measurestring method that used a form that was always around (like your main form/login form or whatever is appropriate) to measure the strings.
    I'm still stumped on this showdialog problem. We have had some success removing third party controls that probably do custom drawing etc, but our app uses a lot of third party controls and it is not acceptable for us to do this to any great extent.

    As far as the cause of the problem goes - I think it has something to do with the order in which the win32 window handles are created and how that differs when you call showdialog vs. show. I think the problem we are having is caused by something trying to draw using GDI (GDI+ is ultimately dependant on GDI) without a valid window handle. I'm not really sure, I'm not an expert on win32 and GDI/user32.dll.

    I would love to hear about any solutions you discovered to this problem though.

  • Recursio

    Error dump...

    [Header]
    2006-05-19 13:58:47,757 [12292] ERROR CentralOrders.SystemFrameworks.Logger [] <> - External component has thrown an exception.

    2006-05-19 13:58:47,850 [12292] ERROR CentralOrders.SystemFrameworks.Logger [] <> - System.Runtime.InteropServices.SEHException: External component has thrown an exception.
    at CentralOrders.GUI.OrderMaintenance.InitializeComponent()
    at CentralOrders.GUI.OrderMaintenance.InitializeAll()
    at CentralOrders.GUI.OrderMaintenance..ctor(OrderMode orderMode, CentralOrder order)
    at CentralOrders.GUI.MainScreen.EditExistingOrder()
    at CentralOrders.GUI.MainScreen.grdSearchResults_DoubleClick(Object sender, EventArgs e)
    at System.Windows.Forms.Control.OnDoubleClick(EventArgs e)
    at C1.Win.C1FlexGrid.C1FlexGridBase.OnDoubleClick(EventArgs e)
    at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
    at System.Windows.Forms.Control.WndProc(Message& m)
    at C1.Win.C1FlexGrid.Util.BaseControls.ScrollableControl.WndProc(Message& m)
    at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
    at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
    at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)------


  • kdlady1974

    I'm in the process of trying to repo this bug in a smaller project so that we can open a support call with MS et al and get this sorted. I'm in my second day of trying to get this going - do you have any ideas about simple repo steps
    At the moment I've worked out that some of our DevExpress XtraEditors controls can cause the problem so I'm trying to repo the error using them in a smaller, simpler project.

    BTW, I would appreciate any obscure words that you've had joy with plugging into google as I think you're finding some results that I haven't been able to locate that might help me with the repo project. Any links about the win32/GDI connection would be appreciated too.

    Cheers,
    Seth.

  • Greg Beam

    Sorry Seth, no idea on repo steps....in the application i'm experiencing this with, the problem is so completely random its almost impossible to repo. Just happens at the worst possible moment, such as in the middle of a demonstration to directors... !

    As you can see from my stack trace, I'm using the Component One FlexGrid control....I have to use this though, it's integral to my application. This does use a lot of drawing routines for setting CellStyle etc, but I'm not convinced that this is the problem - some screens that do not use this control kick out the problem.

    The link in one of my posts above has some decent information....someone seems to suggest that a window handle is not destroyed on a form instance, which then causes all future constructs to fail Threading model is also discussed....I dont think this applies to me, I'm going to spend time looking for invalid handles. I suppose the way to get to the bottom of this is to wait until your application starts kicking out the error, then use Spy++ to look for any handles that look suspicious and see what owns them (tedious). This should then tell you at least what is causing the problem....if not why it's happening.

    As far as links goes, I've just been googling for the whole 'External Component has thrown an exception' phrase...I've had to wade through a lot of web application posts, but every now and then I've hit upon something that was relevant to me. Sorry, haven't saved the links but I'll check my history and see if any visited sites look familiar.

    Again, if I get any further with this problem I'll post back in this thread.

    Also...if any Microsoft employees \ Winforms experts happen to read this post, it'd be nice if you could confirm or deny any of my wild speculations... ! Just so we know we're looking in the right places..!

    Cheers


  • gswitz

    No-one has ever heard of this or can think of anything that could cause it !!


  • schmidj

    Can anyone from MS help with this or point me in a direction A bit more information...

    • Application is written in C#
    • The Citrix machines running the application are on Windows 2000.
    • Only seems to happen in thin-client mode. I don't experience it on my dev machine.
    • Application runs from a network share, hosted on a windows server.
    • The application is using remoting over TCP, this provides all the business objects and various data (DAL). Most forms will be retriving data as they construct.
    • Only seems to happen on forms been displayed with .ShowDialog()
    • Once a form has this error, it cannot be opened again until the application is shut down and restarted.

    It seems I'm not alone with this problem, this thread has most in common with the symptons I'm experiencing...(post by Charles at the bottom)

    http://www.dotnet247.com/247reference/msgs/57/285567.aspx

    When I finally deploy, I think I'll be installing on the servers & using NGEN. Maybe this will solve the issue, could it be the forms are trying to construct & having a problem with JIT when running from the network share

    If I can give any more information that might help solve, please let me know. As it is, I'm really not confident about rolling out my application with unexplained, random exceptions.

    Thanks


  • Morten Nielsen

    Fair play on giving up on it for the meantime - I'm extremely keen to move onto v2 (generics is a good enough reason for me), but I'm sure there have been various other improvements as far as Winforms goes.

    Unfortunately, my company are being a bit draconian with the purse strings and software upgrades are usually the first thing to get cut from the budget. I've got a couple of months before my app goes live, I reckon I'll convince them to upgrade by then...!

    To be honest, this is the only real show-stopper I have experienced with v1.1...sounds like you've had much more drama.

    Cheers

    Dylan


  • Lenny Hoffman

    I'll check on objects, but I'm not sure if that's going to be the issue. Forgot to mention, I'm not getting this problem on any 'fat clients', only when running the application through terminal services.

    Perhaps something installed on the server that is conflicting


  • External component has thrown an exception