new PathGeometry()抛出TypeInitializationException?

时间:2012-09-24 12:53:19

标签: c# wpf pathgeometry

我有一个程序在后台线程中进行一些几何分析。

通常这种方法效果很好,但令人惊讶的是,现在我尝试在开发计算机上创建PathGeometry时遇到异常:

所以简单的代码:

PathGeometry geometry = new PathGeometry();

我得到一个System.TypeInitializationException {“DerTypeninitialisiererfür\”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.Win32Exception {“UngültigesFensterhandle”} 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都会抛出代码。

1 个答案:

答案 0 :(得分:0)

当本机CreateWindowEx()api函数调用失败时,您将获得此堆栈跟踪。失败的原因很少,只有一个。您的程序可能会遇到句柄泄漏,消耗10,000个窗口句柄。 Windows拒绝让你创建更多。

使用Taskmgr.exe进行诊断,进程选项卡。查看+选择列,勾选用户对象。同时勾选Handles和GDI Objects,以防万一。观察过程的显示值。 USER Objects的稳定攀升值令人沮丧。找到泄漏的原因可能有点困难。当然要考虑一个内存分析器。任意评论出大量的代码。如果你没有在Taskmgr.exe中看到泄漏,那么还有一些其他的过程会弄乱你的。任意杀死他们,找到麻烦制造者。

最后但同样重要的是,看到工作线程创建一个窗口是一个麻烦的方法。我对PathGeometry知之甚少,但它看起来不像那种可以在工作者上正常运行的类。