C# 带有Datagrid的窗口上的ShowDialog()抛出一个dividebyzero错误
我发现了一个奇怪的bug,我甚至找不到它的来源: 我有一个窗口,其中DataGrid绑定到从数据集填充的静态资源: WPF: 用户完成将设置写入设置文件后,会出现此问题。在上一个窗口(带有DataGrid的窗口)上尝试运行ShowDialog()时,它会抛出一个C# 带有Datagrid的窗口上的ShowDialog()抛出一个dividebyzero错误,c#,wpf,datagrid,C#,Wpf,Datagrid,我发现了一个奇怪的bug,我甚至找不到它的来源: 我有一个窗口,其中DataGrid绑定到从数据集填充的静态资源: WPF: 用户完成将设置写入设置文件后,会出现此问题。在上一个窗口(带有DataGrid的窗口)上尝试运行ShowDialog()时,它会抛出一个System.DivideByZeroException,并具有以下堆栈跟踪: em System.Windows.Controls.VirtualizingStackPanel.MeasureOverrideImpl(Size c
System.DivideByZeroException
,并具有以下堆栈跟踪:
em System.Windows.Controls.VirtualizingStackPanel.MeasureOverrideImpl(Size constraint, Nullable`1& lastPageSafeOffset, List`1& previouslyMeasuredOffsets, Nullable`1& lastPagePixelSize, Boolean remeasure)
em System.Windows.Controls.VirtualizingStackPanel.MeasureOverride(Size constraint)
em System.Windows.Controls.Primitives.DataGridRowsPresenter.MeasureOverride(Size constraint)
em System.Windows.FrameworkElement.MeasureCore(Size availableSize)
em System.Windows.UIElement.Measure(Size availableSize)
em MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
em System.Windows.Controls.ItemsPresenter.MeasureOverride(Size constraint)
em System.Windows.FrameworkElement.MeasureCore(Size availableSize)
em System.Windows.UIElement.Measure(Size availableSize)
em MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
em System.Windows.Controls.ScrollContentPresenter.MeasureOverride(Size constraint)
em System.Windows.FrameworkElement.MeasureCore(Size availableSize)
em System.Windows.UIElement.Measure(Size availableSize)
em System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)
em System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV, Boolean& hasDesiredSizeUChanged)
em System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV)
em System.Windows.Controls.Grid.MeasureOverride(Size constraint)
em System.Windows.FrameworkElement.MeasureCore(Size availableSize)
em System.Windows.UIElement.Measure(Size availableSize)
em System.Windows.Controls.ScrollViewer.MeasureOverride(Size constraint)
em System.Windows.FrameworkElement.MeasureCore(Size availableSize)
em System.Windows.UIElement.Measure(Size availableSize)
em System.Windows.Controls.Border.MeasureOverride(Size constraint)
em System.Windows.FrameworkElement.MeasureCore(Size availableSize)
em System.Windows.UIElement.Measure(Size availableSize)
em System.Windows.Controls.Control.MeasureOverride(Size constraint)
em System.Windows.Controls.DataGrid.MeasureOverride(Size availableSize)
em System.Windows.FrameworkElement.MeasureCore(Size availableSize)
em System.Windows.UIElement.Measure(Size availableSize)
em System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)
em System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV, Boolean& hasDesiredSizeUChanged)
em System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV)
em System.Windows.Controls.Grid.MeasureOverride(Size constraint)
em System.Windows.FrameworkElement.MeasureCore(Size availableSize)
em System.Windows.UIElement.Measure(Size availableSize)
em System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)
em System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV, Boolean& hasDesiredSizeUChanged)
em System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV)
em System.Windows.Controls.Grid.MeasureOverride(Size constraint)
em System.Windows.FrameworkElement.MeasureCore(Size availableSize)
em System.Windows.UIElement.Measure(Size availableSize)
em System.Windows.Controls.Border.MeasureOverride(Size constraint)
em System.Windows.FrameworkElement.MeasureCore(Size availableSize)
em System.Windows.UIElement.Measure(Size availableSize)
em System.Windows.Controls.Border.MeasureOverride(Size constraint)
em System.Windows.FrameworkElement.MeasureCore(Size availableSize)
em System.Windows.UIElement.Measure(Size availableSize)
em MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
em System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint)
em System.Windows.FrameworkElement.MeasureCore(Size availableSize)
em System.Windows.UIElement.Measure(Size availableSize)
em System.Windows.Documents.AdornerDecorator.MeasureOverride(Size constraint)
em System.Windows.FrameworkElement.MeasureCore(Size availableSize)
em System.Windows.UIElement.Measure(Size availableSize)
em System.Windows.Controls.Border.MeasureOverride(Size constraint)
em System.Windows.FrameworkElement.MeasureCore(Size availableSize)
em System.Windows.UIElement.Measure(Size availableSize)
em System.Windows.Window.MeasureOverrideHelper(Size constraint)
em System.Windows.Window.MeasureOverride(Size availableSize)
em System.Windows.FrameworkElement.MeasureCore(Size availableSize)
em System.Windows.UIElement.Measure(Size availableSize)
em System.Windows.Interop.HwndSource.SetLayoutSize()
em System.Windows.Interop.HwndSource.set_RootVisualInternal(Visual value)
em System.Windows.Interop.HwndSource.set_RootVisual(Visual value)
em System.Windows.Window.SetRootVisual()
em System.Windows.Window.SetRootVisualAndUpdateSTC()
em System.Windows.Window.SetupInitialState(Double requestedTop, Double requestedLeft, Double requestedWidth, Double requestedHeight)
em System.Windows.Window.CreateSourceWindow(Boolean duringShow)
em System.Windows.Window.CreateSourceWindowDuringShow()
em System.Windows.Window.SafeCreateWindowDuringShow()
em System.Windows.Window.ShowHelper(Object booleanBox)
em System.Windows.Window.Show()
em System.Windows.Window.ShowDialog()
em PDV_WPF.Telas.Caixa.<>c__DisplayClass80_0.<MainWindow_KeyDown>b__14(Object p) na M:\TrilhaWS\InfoSales\PDV_PRINCIPAL\Telas\Caixa.xaml.cs:linha 1311
em PDV_WPF.DebounceDispatcher.<>c__DisplayClass5_0.<Debounce>b__0(Object s, EventArgs e) na M:\TrilhaWS\InfoSales\PDV_PRINCIPAL\Funcoes\PublicFunc.cs:linha 2062
em System.Windows.Threading.DispatcherTimer.FireTick(Object unused)
em System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
em System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
em System.Windows.Threading.DispatcherOperation.InvokeImpl()
em System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
em MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj)
em System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
em System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
em System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
em MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
em System.Windows.Threading.DispatcherOperation.Invoke()
em System.Windows.Threading.Dispatcher.ProcessQueue()
em System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
em MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
em MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
em System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
em System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
em System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
em MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
em MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
em System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
em System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
em System.Windows.Application.RunDispatcher(Object ignore)
em System.Windows.Application.RunInternal(Window window)
em System.Windows.Application.Run(Window window)
em System.Windows.Application.Run()
em PDV_WPF.App.Main()
调用封送处理方法后,每当呈现数据网格时,ShowDialog()
方法抛出System.DivideByZeroException
第二次编辑:我已经找到了为什么我会出现这个错误。DllImport首先在SysWOW64文件夹中查找dllsat.dll,其中有一个错误的旧版本的dll。当我从SysWOW64中删除该文件,并强制构建操作“始终复制”dll的正确版本时,它工作得非常完美
我应该把这篇文章作为我自己问题的答案吗?我已经找到了为什么会出现这个错误。DllImport首先在SysWOW64文件夹中查找dllsat.dll,其中有一个错误的旧版本的dll。当我从SysWOW64中删除该文件,并强制构建操作“始终复制”dll的正确版本时,它工作得非常完美
根据Steffen的建议在此处发布作为答案。“我是否应该将此作为我自己问题的答案发布?”是的,请发布。其他有类似问题的人可能会看到此问题,但也会看到0答案并跳过它。
public setupSpooler()
{
InitializeComponent();
foreach (string printer in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
{
cbb_printers.Items.Add(printer);
}
}
private void cbb_printers_DropDownClosed(object sender, EventArgs e)
{
if (cbb_printers.SelectedIndex.ToString() != "-1")
{
Properties.Settings.Default.ImpressoraUSB = cbb_printers.SelectedItem.ToString();
Properties.Settings.Default.Save();
Properties.Settings.Default.Reload();
}
}
em System.Windows.Controls.VirtualizingStackPanel.MeasureOverrideImpl(Size constraint, Nullable`1& lastPageSafeOffset, List`1& previouslyMeasuredOffsets, Nullable`1& lastPagePixelSize, Boolean remeasure)
em System.Windows.Controls.VirtualizingStackPanel.MeasureOverride(Size constraint)
em System.Windows.Controls.Primitives.DataGridRowsPresenter.MeasureOverride(Size constraint)
em System.Windows.FrameworkElement.MeasureCore(Size availableSize)
em System.Windows.UIElement.Measure(Size availableSize)
em MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
em System.Windows.Controls.ItemsPresenter.MeasureOverride(Size constraint)
em System.Windows.FrameworkElement.MeasureCore(Size availableSize)
em System.Windows.UIElement.Measure(Size availableSize)
em MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
em System.Windows.Controls.ScrollContentPresenter.MeasureOverride(Size constraint)
em System.Windows.FrameworkElement.MeasureCore(Size availableSize)
em System.Windows.UIElement.Measure(Size availableSize)
em System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)
em System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV, Boolean& hasDesiredSizeUChanged)
em System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV)
em System.Windows.Controls.Grid.MeasureOverride(Size constraint)
em System.Windows.FrameworkElement.MeasureCore(Size availableSize)
em System.Windows.UIElement.Measure(Size availableSize)
em System.Windows.Controls.ScrollViewer.MeasureOverride(Size constraint)
em System.Windows.FrameworkElement.MeasureCore(Size availableSize)
em System.Windows.UIElement.Measure(Size availableSize)
em System.Windows.Controls.Border.MeasureOverride(Size constraint)
em System.Windows.FrameworkElement.MeasureCore(Size availableSize)
em System.Windows.UIElement.Measure(Size availableSize)
em System.Windows.Controls.Control.MeasureOverride(Size constraint)
em System.Windows.Controls.DataGrid.MeasureOverride(Size availableSize)
em System.Windows.FrameworkElement.MeasureCore(Size availableSize)
em System.Windows.UIElement.Measure(Size availableSize)
em System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)
em System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV, Boolean& hasDesiredSizeUChanged)
em System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV)
em System.Windows.Controls.Grid.MeasureOverride(Size constraint)
em System.Windows.FrameworkElement.MeasureCore(Size availableSize)
em System.Windows.UIElement.Measure(Size availableSize)
em System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)
em System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV, Boolean& hasDesiredSizeUChanged)
em System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV)
em System.Windows.Controls.Grid.MeasureOverride(Size constraint)
em System.Windows.FrameworkElement.MeasureCore(Size availableSize)
em System.Windows.UIElement.Measure(Size availableSize)
em System.Windows.Controls.Border.MeasureOverride(Size constraint)
em System.Windows.FrameworkElement.MeasureCore(Size availableSize)
em System.Windows.UIElement.Measure(Size availableSize)
em System.Windows.Controls.Border.MeasureOverride(Size constraint)
em System.Windows.FrameworkElement.MeasureCore(Size availableSize)
em System.Windows.UIElement.Measure(Size availableSize)
em MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
em System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint)
em System.Windows.FrameworkElement.MeasureCore(Size availableSize)
em System.Windows.UIElement.Measure(Size availableSize)
em System.Windows.Documents.AdornerDecorator.MeasureOverride(Size constraint)
em System.Windows.FrameworkElement.MeasureCore(Size availableSize)
em System.Windows.UIElement.Measure(Size availableSize)
em System.Windows.Controls.Border.MeasureOverride(Size constraint)
em System.Windows.FrameworkElement.MeasureCore(Size availableSize)
em System.Windows.UIElement.Measure(Size availableSize)
em System.Windows.Window.MeasureOverrideHelper(Size constraint)
em System.Windows.Window.MeasureOverride(Size availableSize)
em System.Windows.FrameworkElement.MeasureCore(Size availableSize)
em System.Windows.UIElement.Measure(Size availableSize)
em System.Windows.Interop.HwndSource.SetLayoutSize()
em System.Windows.Interop.HwndSource.set_RootVisualInternal(Visual value)
em System.Windows.Interop.HwndSource.set_RootVisual(Visual value)
em System.Windows.Window.SetRootVisual()
em System.Windows.Window.SetRootVisualAndUpdateSTC()
em System.Windows.Window.SetupInitialState(Double requestedTop, Double requestedLeft, Double requestedWidth, Double requestedHeight)
em System.Windows.Window.CreateSourceWindow(Boolean duringShow)
em System.Windows.Window.CreateSourceWindowDuringShow()
em System.Windows.Window.SafeCreateWindowDuringShow()
em System.Windows.Window.ShowHelper(Object booleanBox)
em System.Windows.Window.Show()
em System.Windows.Window.ShowDialog()
em PDV_WPF.Telas.Caixa.<>c__DisplayClass80_0.<MainWindow_KeyDown>b__14(Object p) na M:\TrilhaWS\InfoSales\PDV_PRINCIPAL\Telas\Caixa.xaml.cs:linha 1311
em PDV_WPF.DebounceDispatcher.<>c__DisplayClass5_0.<Debounce>b__0(Object s, EventArgs e) na M:\TrilhaWS\InfoSales\PDV_PRINCIPAL\Funcoes\PublicFunc.cs:linha 2062
em System.Windows.Threading.DispatcherTimer.FireTick(Object unused)
em System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
em System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
em System.Windows.Threading.DispatcherOperation.InvokeImpl()
em System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
em MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj)
em System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
em System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
em System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
em MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
em System.Windows.Threading.DispatcherOperation.Invoke()
em System.Windows.Threading.Dispatcher.ProcessQueue()
em System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
em MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
em MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
em System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
em System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
em System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
em MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
em MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
em System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
em System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
em System.Windows.Application.RunDispatcher(Object ignore)
em System.Windows.Application.RunInternal(Window window)
em System.Windows.Application.Run(Window window)
em System.Windows.Application.Run()
em PDV_WPF.App.Main()
[DllImport("dllsat.dll", CallingConvention = CallingConvention.StdCall)]
public static extern IntPtr Query(int sessionNo);