[CLOSED] messagebox throwing null reference exception

  1. #1

    [CLOSED] messagebox throwing null reference exception

    Although I have used messagebox at many places in my code and it works fine, but it's not working at one place(below given code) and giving "null reference exception" in it.

    private void LoadExcelFile(System.Windows.Forms.OpenFileDialog openFileDialog)
            {
                excelFile = ExcelFile.Load(openFileDialog.FileName);
                // Select the first worksheet from the file.
                excelWorkSheet = excelFile.Worksheets[0];
                if (!IsWorkSheetEmpty(excelWorkSheet))
                {
                    options = new ExtractToDataTableOptions(0, 0, excelFile.Worksheets[0].Rows.Count);
                    options.ExtractDataOptions = ExtractDataOptions.StopAtFirstEmptyRow;
                    options.ExcelCellToDataTableCellConverting += (sender, e) =>
                    {
                        if (!e.IsDataTableValueValid)
                        {
                            // GemBox.Spreadsheet doesn't automatically convert numbers to strings in ExtractToDataTable() method because of culture issues; 
                            // someone would expect the number 12.4 as "12.4" and someone else as "12,4".
                            e.DataTableValue = e.ExcelCellValue == null ? null : e.ExcelCellValue.ToString();
                            e.Action = ExtractDataEventAction.Continue;
                        }
                    };
                }
                else
                {
                    //X.Msg.Alert("Error", "File is Empty.").Show();
                    X.Msg.Show(new MessageBoxConfig
                    {
                        Title = "Error",
                        Message = "Excel file is empty",
                        Buttons = MessageBox.Button.OK
                    });
                }
    }
    anyone please tell me what wrong I am doing here
    Last edited by Daniil; Feb 25, 2015 at 9:13 AM. Reason: [CLOSED]
  2. #2
    Helo, sharmav1!

    I believe the error is not in the code you pasted, it seems okay.

    The problem should be in the context of the whole. It seems it is an action bound to a button you click to download an excel spreadsheet.

    If that is right (and I can naught but base on assumptions as I can't see the rest of the code), then I believe your button have a special working mechanism so it works for downloading files. Something to do with its POST method.

    So, when you try to encapsulate script code (as the message dialog is returned back to the page), havoc will likely break. An alternative would be to make an Excel file or PDF file containing the no data or the error message, or work on a different approach to download the file. Not that it is ideal to every scenario.

    If what I said does not help, can you provide a working, simplified code reproducing the issue, so we can run here and point you the real cause and likely the solution?

    If in doubt how to proceed from this point on, these forum posts are your friends:
    - Forum Guidelines For Posting New Topics
    - More information required
    Fabrício Murta
    Developer & Support Expert

Similar Threads

  1. Replies: 3
    Last Post: Jan 07, 2015, 6:29 PM
  2. [CLOSED] very strange null reference exception?
    By tobros in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Aug 01, 2013, 2:04 AM
  3. Null Reference Exception in MVC
    By geraldf in forum 2.x Help
    Replies: 1
    Last Post: Sep 07, 2012, 6:11 PM
  4. [CLOSED] [1.0] Calendar throwing exception
    By Timothy in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Mar 25, 2011, 12:21 AM
  5. Replies: 1
    Last Post: Jun 08, 2010, 11:38 AM

Posting Permissions