Assembly.GetTypes()在.NET 4.0上无限挂起 [英] Assembly.GetTypes() hangs infinitely on .NET 4.0

查看:130
本文介绍了Assembly.GetTypes()在.NET 4.0上无限挂起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我们正在开发.NET 4.0 WPF应用程序,但遇到了一个非常奇怪的问题.我们只是在调用Assembly.GetTypes,但是由于某种原因它从未完成.而且,它正在使用一个处理器内核的100%.

We're developing a .NET 4.0 WPF application and we ran into very strange problem. We're simply calling Assembly.GetTypes but for some reason it never completes. Also, it is using 100% of one processor core.

即使以下简单的控制台应用程序也永远无法完成:

Even the following simple console application never completes:

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var assembly = typeof(MyLibrary.MyType).Assembly;
            var types = assembly.GetTypes();
        }
    }
}

在这种情况下,MyLibrary.MyType驻留在另一个我在此控制台应用程序中引用过的程序集中.此外,该程序集还有许多其他参考,但我了解到,如果在加载这些其他参考时遇到任何问题,则会出现异常 应该抛出而不是无限地挂起.

In this case MyLibrary.MyType lives in another assembly to which I have reference in this console application. Also, the assembly has many other references but I have understood that if there were any problems in loading these other references, an exception should be thrown instead of hanging infinitely.

我从调试选项中关闭了我的代码",似乎是以下几行引起了该问题:

I turned Just My Code off from debugging options and it seems that following line is causing the problem:

SystemEvents.cs line 1569 int ret = UnsafeNativeMethods.MsgWaitForMultipleObjectsEx(0, IntPtr.Zero, 100, NativeMethods.QS_ALLINPUT, NativeMethods.MWMO_INPUTAVAILABLE);

可能是什么问题?这是.NET 4.0中的错误吗?有办法以某种方式调试它吗?在已安装.NET 4.5的计算机上,这可以完美地工作.我们已经在Win7和Win8上对此进行了测试.

What could be the problem? Is this a bug in .NET 4.0? Is there a way to debug this somehow? On a computer that has .NET 4.5 installed this works perfectly. We have tested this both on Win7 and Win8.

谢谢!

推荐答案

我们一直在使用这种类型的代码,并且没有任何问题.您提到的呼叫是等待Windows消息的阻止呼叫. AFAIK GetTypes不会这样称呼,因为GetTypes不会阻塞任何东西.发生这个问题了吗 仅在一台或多台机器上?调试该应用程序,当它遇到GetTypes调用时,然后使用调试器进行干预并获取调用堆栈信息.

We use this type of code all the time and we're not having any issues.  The call you mention is a blocking call waiting for a Windows message.  AFAIK GetTypes wouldn't call that as GetTypes isn't blocking on anything.  Is this problem occurring only on 1 machine or several?  Debug the app and when it hits the GetTypes call then break in using the debugger and get the call stack information.

问题是否在不同的程序集上发生?您是否有任何静态的构造函数在进行冗长的工作,可能会拖延类型的负担?

Does the problem occur with a different assembly?  Do you have any static constructors that are doing lengthy work that could stall the load of the types?

迈克尔·泰勒
http://msmvps.com/blogs/p3net

Michael Taylor
http://msmvps.com/blogs/p3net


这篇关于Assembly.GetTypes()在.NET 4.0上无限挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆