我的WPF测试应用程序(非常简单,只有一个窗口)正在使用第三方受管dll(如X.dll)。这个托管的DLL使用一些非托管的DLL。 所以我们可以说我写了一个小的wpf应用程序,它只是引用了X.dll。在窗口的构造函数中,我可以访问X.dll中的某些东西(即在X.dll中的某些命名空间中)。在这样做我不会捕捉任何异常,它似乎像事情正在按预期进行。但在返回控制到.NET运行时,我得到了应用程序类的“DispatcherUnhandledException”处理异常:“在算术运算溢出或下溢”“算术运算中溢出或下溢”WPF特定问题
System.ArithmeticException了未处理 消息 =“溢出或在算术运算中下溢。“
来源 = “PresentationFramework”
堆栈跟踪:
System.Windows.Window.ValidateTopLeft(Double length)
System.Windows.Window.CoerceTop(DependencyObject d, Object value) System.Windows.DependencyObject.ProcessCoerceValue(DependencyProperty dp, PropertyMetadata metadata, EntryIndex& entryIndex, Int32& targetIndex, EffectiveValueEntry& newEntry, EffectiveValueEntry& oldEntry, Object& oldValue, Object baseValue, CoerceValueCallback coerceValueCallback, Boolean coerceWithDeferredReference, Boolean skipBaseValueChecks)
System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, OperationType operationType)
System.Windows.DependencyObject.CoerceValue(DependencyProperty dp) at System.Windows.Window.SetupInitialState(Double requestedTop, Double requestedLeft, Double requestedWidth, Double requestedHeight)
System.Windows.Window.CreateSourceWindowImpl() at System.Windows.Window.SafeCreateWindow() at System.Windows.Window.ShowHelper(Object booleanBox)
System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
几点:
- 这只发生在WPF应用程序,而不是在WinForms应用程序。
- 这不会被抓住试试看。只在应用程序的DispatcherUnhandledException
- 这不会发生,如果我访问窗口的'Loaded'事件中的X.dll的代码,只发生在构造函数。
任何人都可以猜出问题吗?
感谢, 米沙勒
当你说“访问”,你的意思是你传递的值作为参数的东西,对不对?你通过了什么? – Jay 2010-03-09 18:15:22
如果我访问/读取整数XNameSpace.AStaticClass.StatInt(其中的XNamespace里面X.dll命名空间),并将其存储在另一个整数,我看到这一点。此外,我看到如果我把这个陈述放在try catch中,那么它就不会被捕获。它只会在System.Window.Application的DispatcherUnhandledException处理程序中被捕获......这真的很奇怪。 – mishal153 2010-03-11 15:09:42