I was using NTwain 3.3.9.2 in my application and it really worked well for all most all features that I tested so far. Thank you very much for the great library. I tested almost all features including Barcode detection, Patch codes and everything worked fine and we deployed our application as a pilot (beta) test in one of our customer's production environment. They reported an issue that on paper jam, it crashing the application with System.NullReferenceException. They were testing with Panasonic 2048 and Canon 1130g. We used Fujitsu fi-7160 scanner for testing and we were able to reproduce the same issue.
The issue happening at line number 110 in TrasnferLogic.cs when it calls EndTransfer.
rc = session.DGControl.PendingXfers.EndXfer(pending);
The actual exception was thrown by the line number 23 from DGControl.PendingXfers.cs and when I debugged it from Visual Studio, Session.CurrentSource was null and it was trying to use Session.CurrentSource.Identity and causing System.NullReferenceException.
Eugene Wang, could you please help me with this?
Here is the complete stack trace.
Exception: Object reference not set to an instance of an object. Type: System.NullReferenceException Source: NTwain StackTrace: at NTwain.Triplets.PendingXfers.EndXfer(TWPendingXfers pendingXfers) in D:\Apps\Twain\Ref\projects\ntwain\src\NTwain\Triplets\DGControl\DGControl.PendingXfers.cs:line 23 at NTwain.Internals.TransferLogic.DoTransferRoutine(ITwainSessionInternal session) in D:\Apps\Twain\Ref\projects\ntwain\src\NTwain\Internals\TransferLogic.cs:line 110 at NTwain.TwainSession.HandleSourceMsg(Message msg) in D:\Apps\Twain\Ref\projects\ntwain\src\NTwain\TwainSessionInternal.cs:line 297 at NTwain.TwainSession.<>c__DisplayClass37_0.<HandleCallback>b__0() in D:\Apps\Twain\Ref\projects\ntwain\src\NTwain\TwainSessionInternal.cs:line 279 at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler) at System.Windows.Threading.DispatcherOperation.InvokeImpl() at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(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.Windows.Threading.DispatcherOperation.Invoke() at System.Windows.Threading.Dispatcher.ProcessQueue() at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler) at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs) at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam) at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg) at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame) at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame) at System.Windows.Threading.Dispatcher.Run() at NTwain.Internals.InternalMessageLoopHook.<>c__DisplayClass3_1.<Start>b__0() in D:\Apps\Twain\Ref\projects\ntwain\src\NTwain\Internals\InternalMessageLoopHook.cs:line 45 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()
The only way for the source to be null should be when it's closed (DataSource.Close() is called). Is the application closing the source on some error condition?