Hi all,
I have a problem with the Bitmap constuctor in .NET - it works fine in Windows 7, but throws an ArgumentException in XP, which is doubly confusing as according to MSDN documentation, the only exception thrown by the Bitmap constructor is a FileNotFoundException.
As part of a project I am working on, there is a class which an extension of the Button class. Within this there is BackgroundImageName property, which takes the name of an image file (in a known location) and then sets the background image of the button to this (there are reasons for it working this way).
The Setting code for this property is below:
public String BackgroundImageName {
get { return _BackgroundImage; }
set {
_BackgroundImage = value;
if (String.IsNullOrEmpty(_BackgroundImage)) {
base.BackgroundImage = null;
}
else {
String ImagePath = Path.Combine(_ImagePath, _BackgroundImage);
base.BackgroundImage = new Bitmap(ImagePath);
}
}
}
I have isolated the code and the line that throws the exception is 100% definitely
base.BackgroundImage = new Bitmap(ImagePath);
(not the Path.Combine call).
The files definitely exist, and they are also small so there should be no memory issues. _ImagePath is a known folder location.
Like I said, this code works perfectly on Windows 7, but falls over completely in Windows XP with the Argument exception.
What makes this weirder is that when the objects are first loaded on XP, it DOES work. Only when you programmatically try to call this setter does it fall down. And once it has fallen down, it then falls down everywhere in the program.
I am at a loss and any suggestions or more detailed knowledge of the Bitmap class would be greatly appreciated - thank you.