none
A generic error occurred in GDI+ RRS feed

  • Question

  • Dear experts,

    I am getting "A generic error occurred in GDI+". error whenever I am performing any image upload after deploying dlls in the server, however I have checked in my local environment and it is working fine. I checked whether the bitmap objects were disposed or not and have found those were disposed. Could you please help me in this? Its been 3 days that I am stuck with. Below is my code. Eagerly waiting for F1

    protected void bttnImageUpload_Click(object sender, EventArgs e)
            {
                Album _album;
                Bitmap _bmp = null;
                Drawing.Image largeImg = null;
                Guid _instanceId = ViewState["_instanceId"] == null ? Guid.Empty : new Guid(Convert.ToString(ViewState["_instanceId"]));
                if (!fuGalleryImage.HasFile)
                {
                    ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(),
                                                        "key", "<script>alert('No File Selected.')</script> ", false);
                }
                else
                {
                    _album = new Album();
                    _album.Name = txtAlbumName.Text;
                    _album.Id = new Guid(ddlSelectAlbum.SelectedValue);
                    foreach (HttpPostedFile _file in fuGalleryImage.PostedFiles)
                    {
                        try
                        {
                            #region [Save Large Image] 
                            //"/Uploads/Gallery/"
                            _album.Story.SystemPath = string.Concat(Server.MapPath(UISettings.GalleryRootFolder), _file.FileName);
                            _album.Story.ServerPath = string.Concat(UISettings.AdminSiteURL, UISettings.GalleryRootFolder.Replace("\\", "/"), _file.FileName);
                            _file.SaveAs(_album.Story.SystemPath);
    
                            largeImg = System.Drawing.Image.FromFile(_album.Story.SystemPath);
                            long fileLength = new FileInfo(_album.Story.SystemPath).Length;
    
                            _album.Story.ContentType = _file.ContentType;
                            _album.Story.Name = fuGalleryImage.FileName;
    
                            #region [Save Thumbnail Image]
    
                            _bmp = CreateThumbnail(_album.Story.SystemPath, 300, 300, true);
                            _album.Story.ThumbnailSystemPath = string.Concat(Server.MapPath(UISettings.GalleryThumbRootFolder), _file.FileName);
                            _album.Story.ThumbnailServerPath = string.Concat(UISettings.AdminSiteURL, UISettings.GalleryThumbRootFolder.Replace("\\", "/"), _file.FileName);
                            _bmp.Save(_album.Story.ThumbnailSystemPath, ImageFormat.Png);
    
    
    
                            #endregion
    
    
                            if (largeImg.Height <= (UISettings.LargeImageHeight)
                                   && largeImg.Width <= (UISettings.LargeImageWidth) && fileLength < UISettings.MaximumLargeImageSizeinByte)
                            {
                                ReturnCode _retCode = AlbumEntityServices.AddImagesIntoTemporaryAlbum(_album, _instanceId);
                            }
                            else
                            {
                                tdSuccess.Visible = false;
                                tdUnsuccess.Visible = true;
                                lblError.Text += string.Format("<br/> Please check the file size and Pixel. FileName: {0}, Allowed Maximum Pixel: {1}x{2}, Maximum Size:{3}",
                                    _file.FileName, UISettings.LargeImageWidth, UISettings.LargeImageHeight, UISettings.MaximumLargeImageSizeinByte, " byte");
    
                              
    
                                ParishadSystemFiles.DeleteFile(_album.Story.SystemPath);
                                ParishadSystemFiles.DeleteFile(_album.Story.ThumbnailSystemPath);
                            }
                            
                            #endregion
                        }
                        catch(Exception ex)
                        {
                            tdUnsuccess.Visible = true;
                            tdSuccess.Visible = false;
                            lblError.Text = ex.Message.ToString(); 
                        }
                        #region [Dispose the image object otherwise it will throw file access denied error]
                        largeImg.Dispose();
                        _bmp.Dispose();
                        #endregion
    
                    }
    
                    _tempAlbumStory = AlbumEntityServices.GetTemporaryImages(_instanceId);
                    gvTempGallery.DataSource = _tempAlbumStory;
                    gvTempGallery.DataBind();
                }
            }

    Sunday, May 27, 2018 4:03 PM

All replies

  • What do you mean with disposed. In .Net "disposed" means made unusable but still referenced.  

    Success
    Cor

    Sunday, May 27, 2018 5:01 PM
  • I meant to say I have used .Dispose() method for the bitmap objects.
    Sunday, May 27, 2018 5:17 PM
  • Have you tried the same image files on server and in your local environment?

    Does it fail for any files, or only for some specific ones?


    Sunday, May 27, 2018 7:10 PM
  • I've seen a message from a guy in these forums who is real good with GDI (drawing) in that he has shown that dispose can be the cause of your kind of problems. '

    Try just for a try to remove those dispose methods. Don't ask me to find it again for you.


    Success
    Cor


    Sunday, May 27, 2018 7:33 PM