【发布时间】:2011-01-25 07:25:12
【问题描述】:
我的 WPF 测试应用程序(非常简单,只有一个窗口)正在使用第 3 方托管的 dll(比如 X.dll)。此托管 dll 使用一些非托管 dll 的 . 因此,假设我编写了一个仅引用 X.dll 的小型 wpf 应用程序。在窗口的构造函数中,我访问了 X.dll 中的某些内容(即在 X.dll 中的某个命名空间中)。在这样做时,我没有发现任何异常,而且事情似乎正在按预期进行。但是在将控件返回到 .NET 运行时,我在 Application 类的“DispatcherUnhandledException”处理程序中得到一个异常:
“算术运算中的上溢或下溢。”
System.ArithmeticException 未处理
Message="算术运算中的溢出或下溢。"
来源="PresentationFramework"
StackTrace:
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 应用程序中。
- 这不会被 try-catch 捕获。仅在应用程序的 DispatcherUnhandledException 中
- 如果我在 Window 的“Loaded”事件中访问 X.dll 的代码,则不会发生这种情况,只会在构造函数中发生。
谁能猜出问题所在?
谢谢, 米沙尔
【问题讨论】:
-
当您说“访问”时,您的意思是您将值作为参数传递给某些东西,对吗?你把它传递给什么?
-
如果我访问/读取整数 XNameSpace.AStaticClass.StatInt(其中 XNamespace 是 X.dll 中的命名空间)并将其存储在另一个整数中,我会看到这一点。此外,我看到如果我将语句放在 try catch 中,它就不会被捕获。它只在 System.Window.Application 的 DispatcherUnhandledException 处理程序中被捕获......这真的很奇怪。