Object Reference Not Set

28 views
Skip to first unread message

Peter Annandale

unread,
Aug 2, 2016, 8:14:48 AM8/2/16
to CSVChat
Further to my previous post here is the stack trace..

   at DataStreams.Xlsx.OOXml.Read.Workbook..ctor(Stream data)
   at DataStreams.Xlsx.XlsxReader..ctor(String fileName)
   at DataStreams.Xlsx.XlsxDataReader..ctor(String fileName)
   at XlsxParser.Form1.validateHeader(FileInfo fi) in c:\users\peter.annadale\documents\visual studio 2015\Projects\XlsxParser\XlsxParser\Form1.cs:line 61
   at XlsxParser.Form1.btnProcess_Click(Object sender, EventArgs e) in c:\users\peter.annadale\documents\visual studio 2015\Projects\XlsxParser\XlsxParser\Form1.cs:line 33
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.Run(Form mainForm)
   at XlsxParser.Program.Main() in c:\users\peter.annadale\documents\visual studio 2015\Projects\XlsxParser\XlsxParser\Program.cs:line 19
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

Regards
Peter.

Peter Annandale

unread,
Aug 2, 2016, 8:14:48 AM8/2/16
to CSVChat
Hi,
    Getting the above error when trying to load an Xlsx file, see code below..
           
            using (XlsxReader xldata = new XlsxReader(fileName)) <--- fails here with the Object Reference not set (xlData is nothing)
            {
                xldata.Settings.HasHeaders = true;

                try
                {
                    if (xldata.HeaderCount == 14) //Production Orders File
                    {

Regards..
Peter

shriop

unread,
Aug 2, 2016, 8:23:24 AM8/2/16
to CSVChat
Most likely, it's not a file made from Excel, it's an xlsx file generated from a third party library and there's some nuance as to how they're generating the file. They've basically been the bane of my existence, trying to keep up with all the ways that they might interpret trying to generate files. If you look at my change log, you'll see quite a few versions made solely to handle these small nuances.

Try opening the file in Excel and saving it, then opening it with the library. Most likely, it will work, meaning that it's not a problem with Excel files.

For a permanent fix in the library, you'd have to email me an example file that I can recreate the issue with and I can evaluate how difficult it would be to build it into the library to handle it.

Bruce Dunwiddie

Peter Annandale

unread,
Aug 2, 2016, 8:06:17 PM8/2/16
to CSVChat
Bruce,
        May well be, the only one I could get to work was the csv (Xls and Xlsx would not work). I have emailed you both files.

Regards..
Peter

shriop

unread,
Aug 3, 2016, 8:14:16 AM8/3/16
to CSVChat
To keep the thread updated, this does appear to be a bug. It may even exist with files generated straight out of Excel. The code is not handling borders on cells correctly in the xlsx format. So far, I have not been able to recreate any issues with the xls format.

Bruce Dunwiddie

shriop

unread,
Aug 7, 2016, 12:22:54 AM8/7/16
to CSVChat
I've released v5.25 with the fix.

Bruce Dunwiddie

Peter Annandale

unread,
Aug 7, 2016, 6:43:43 PM8/7/16
to CSVChat
Have downloaded and testing import on xlsx files produced by SSRS are good.

Regards
Peter
Reply all
Reply to author
Forward
0 new messages