views:

234

answers:

2

Winforms c# application running on terminal server. All images for buttons and menu items are stored as resources in the .resx file. After some heavy use, opening and closing windows while using the system, an "index out of range" exception is thrown and the window no longer opens. If the user attempts to navigate to any other part of the system it fails for the same reason. Narrowed it down to the resources not being able to be loaded anymore.

Does anyone have an idea of what may cause this or how I might be able to avoid it? Should I use a different method for storing my images to be used for my application?

Additional information: turns out the user was receiving a "Parameter is not valid" exception rather than an index out of range.

A: 

It is strange that you receive an out-of-range exception when accessing resources, mainly because the resources are not stored in any kind of collection, there are accessed as properties, so perhaps your exception does not come from there?

Plz provide some code about the way you are retrieving the images/buttons.

netadictos
All buttons are retrieved using the following syntax: button.Image = global::Namespace.Properties.Resources.image_16;I have another picture box that I use and I set it image based on a URL: pictureBox.ImageLocation = URL;I don't have any dispose code for these controls.
ericmck
I think it is ok, but it is not possible to receive an out of range exception, because it is not a collection.
netadictos
Right. I spoke with the user and they said it was a "Parameter is not valid" exception rather than the out of range exception.
ericmck
Look at this web: "The Mysterious Parameter is not valid", it is also a problem of images and memory available, http://blog.lavablast.com/post/2007/11/The-Mysterious-Parameter-Is-Not-Valid-Exception.aspx
netadictos
A: 

Are you releasing the resources after you use them? It sounds like you're running out of resource handles (and the exception you're seeing may be a red herring).

Since these are windows controls whose properties allow for images I didn't think there would be any need for my own releasing of resources. The button and picture box I use should both handle the releasing of the resource when the form and all of it's controls are disposed. Right?
ericmck