Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Value cannot be null. Parameter name: source

Status
Not open for further replies.

Trebor100

Programmer
Mar 14, 2006
90
GB
Hi All - I'm really stuck and need your help.

Background: The error occurs on a photo gallery image approval page and only occurs on approximately 10% of images submitted into the photo gallery.

I’m getting the following error:
Value cannot be null. Parameter name: source

on the PropertyItem line shown below:
Bitmap MyPhoto = new Bitmap(Server.MapPath(".") + "/tmp/" + strFile);
PropertyItem[] props = MyPhoto.PropertyItems;

Does anyone know either a fix or a work around? I’m kind of desperate here!

Cheers all,
Rob
 
nothing appears to be wrong from this segment of code.
are your sure the file exists? try this instead
Code:
string file = Server.MapPath(string.Format("./tmp/{0}", strFile));
if(!File.Exists(file)) throw new Excpetion(file + " is missing!");
PropertyItem[] properties = new BitMap(file).PropertyItems;

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Thanks for the response Jason and I'll give that a go now - the file does exist as the file name is grabbed from a drop down list of files in the tmp area:

DirectoryInfo di = new DirectoryInfo(Server.MapPath(".") + "/tmp");
FileInfo[] rgFiles = di.GetFiles("*.jpg");
foreach(FileInfo fi in rgFiles)
{
ddlImageList.Items.Add(fi.Name.ToString());
}
 
this may be the problem. FileInfo holds a reference to the file. if all you're doing is getting the name I would use this approach instead
Code:
foreach(string file in Directory.GetFiles())
{
   if(!file.EndsWith("jpg") continue;
   ddlImageList.Items.Add(file);
}

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Still no joy mate - File does exist but simply doesnt like reading the properties of the image. I'm starting to fall out with using metadata on images ;)
 
the thing that's bothering me is the error message. no where in the code provided do you have a parameter named source. And MS is usually good about providing details.

could you post the full stacktrace?

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
The exception in full is:

System.ArgumentNullException: Value cannot be null. Parameter name: source at System.Runtime.InteropServices.Marshal.CopyBytesToManaged(Int32 source, Byte[] destination, Int32 startIndex, Int32 length) at System.Runtime.InteropServices.Marshal.Copy(IntPtr source, Byte[] destination, Int32 startIndex, Int32 length) at System.Drawing.Imaging.PropertyItemInternal.get_Value() at System.Drawing.Imaging.PropertyItemInternal.ConvertFromMemory(IntPtr propdata, Int32 count) at System.Drawing.Image.get_PropertyItems() at PhotoGallery.ImageApprove.btnLoad_Click(Object sender, EventArgs e) in c:\inetpub\ 267

Stack trace is:


[ArgumentNullException: Value cannot be null.
Parameter name: source]
System.Runtime.InteropServices.Marshal.CopyBytesToManaged(Int32 source, Byte[] destination, Int32 startIndex, Int32 length) +0
System.Runtime.InteropServices.Marshal.Copy(IntPtr source, Byte[] destination, Int32 startIndex, Int32 length) +26
System.Drawing.Imaging.PropertyItemInternal.get_Value()
System.Drawing.Imaging.PropertyItemInternal.ConvertFromMemory(IntPtr propdata, Int32 count)
System.Drawing.Image.get_PropertyItems()
PhotoGallery.ImageApprove.saveImage() in c:\inetpub\ PhotoGallery.ImageApprove.btnApprove_Click(Object sender, EventArgs e) in c:\inetpub\ System.Web.UI.WebControls.Button.OnClick(EventArgs e)
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain()


I would be much happier if this didnt work at all - however for 90% or so of images submitted to the gallery this error does not happen.

Cheers,
Rob
 
is the error consistent with specific images? or is it a timing issue?

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
with a specific images only. the image is there and opens etc but cannot access the properties of it programatically (ie you can assign the path to an img and it will display on the web).
 
not sure what to make of it then.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
bump - anyone have any thoughts on solving this? If not then any way to just force an over-write of the properties??
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top