我有一个程序,它在一个背景线程中进行一些几何分析。
通常情况下,这工作得很好,但令人惊讶的是,现在我在开发计算机上创建PathGeometry时遇到了一个异常:
因此,对于简单的代码:
PathGeometry geometry = new PathGeometry();
我得到一个System.TypeInitializationException{“Der Typeninitialisierer fr\”System.Windows.Media.PathGeometry\“hat eine Ausnahme verursacht。”}
堆栈跟踪是:
bei System.Windows.Media.PathGeometry..ctor()
bei Bsoft.ilka.AlkisLeser.AlkisDatei.GetPosition(XElement xe) in AlkisDatei.cs:Zeile 267.
此异常包含InnerException System.ComponentModel.Win32异常{“Unltiges Fensterhandle”}
InnerException的堆栈跟踪为:
bei MS.Win32.UnsafeNativeMethods.GetWindowLongWndProc(HandleRef hWnd)
bei MS.Win32.HwndSubclass.UnhookWindowProc(Boolean force)
bei MS.Win32.HwndSubclass.Dispose()
bei MS.Win32.HwndWrapper..ctor(Int32 classStyle, Int32 style, Int32 exStyle, Int32 x, Int32 y, Int32 width, Int32 height, String name, IntPtr parent, HwndWrapperHook[] hooks)
bei System.Windows.Threading.Dispatcher..ctor()
bei System.Windows.Threading.Dispatcher.get_CurrentDispatcher()
bei System.Windows.DependencyObject..ctor()
bei System.Windows.Media.PathFigureCollection.get_Empty()
bei System.Windows.Media.PathGeometry..cctor()
奇怪的是:可执行文件确实在其他计算机上工作。
问题出在哪里?为什么PathGeometry构造函数试图访问某些窗口句柄?我该如何解决此问题?
我使用的是.NET framework 4.0,代码同时抛出VS2010和VS2012。