locked
System.Reflection.TargetInvocationException was unhandled

    Question

  • In my program following line:
    -------------
    this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
    ------------

    is giving System.Reflection.TargetInvocationException was unhandled by user code Message "Exception has been thrown by the target of an invocation."Source="mscorlib"

    Note: It is thrown only when I am out of memory, otherwise it is ok.

    What is the solution?
    some borns good, others make good
    • Edited by cissharp Thursday, November 13, 2008 8:49 AM Information added
    Thursday, November 13, 2008 7:01 AM

Answers

  • It was memory leak problem with GDI objects outrun. Solved it myself. Thanx anyway to all.
    A person who never made a mistake never tried anything new.
    • Marked as answer by cissharp Monday, December 15, 2008 9:35 AM
    Monday, December 15, 2008 9:35 AM

All replies

  • Tell us what is the InnerException of the exception you're getting, that should give us more information.
    Thursday, November 13, 2008 11:53 AM
  • OK, this might not sound helpful - but if it only happens when you are low on memory... use less memory?

    You could try looking at the .InnerException, or GetBaseException() - however, I don't expect they'll be very interesting (it might just be wrapping an OutOfMemoryException, for example).

    Marc [C# MVP]
    Thursday, November 13, 2008 11:54 AM
  • Using Images in applications can be a bit tricky.  Make sure you're disposing them all after using them.  They tend to stick in memory a little longer than needed, and when you load alot of them, you can get a plain ol' vanilla out of memory exception.


    David Morton - http://blog.davemorton.net/
    Thursday, November 13, 2008 3:46 PM
    Moderator
  • It was memory leak problem with GDI objects outrun. Solved it myself. Thanx anyway to all.
    A person who never made a mistake never tried anything new.
    • Marked as answer by cissharp Monday, December 15, 2008 9:35 AM
    Monday, December 15, 2008 9:35 AM