为什么通过反射查询程序集的类型会导致程序在调试时意外挂起?

时间:2013-11-08 16:53:03

标签: c# .net reflection .net-assembly

使用此代码停止响应我的程序。

Assembly assembly = Assembly.LoadFrom(@"C:\test\test.exe");
Type[] typesInAssembly = assembly.GetTypes();

在调试模式下,当第二行执行时,此代码停止响应。

我将test.exe更改为空的WindowsformApplication.exe,它可以运行。 我不知道为什么它不能与test.exe一起使用。 我在调试Locals部分时放了断点并检查了Locals,我看到了一些错误图标,我将它们粘贴在下面。我希望有人帮助我。

    DefinedTypes    Function evaluation timed out.  System.Collections.Generic.IEnumerable<System.Reflection.TypeInfo>
    EntryPoint  Function evaluation disabled because a previous function evaluation timed out. You must continue execution to reenable function evaluation. System.Reflection.MethodInfo
    EscapedCodeBase Function evaluation disabled because a previous function evaluation timed out. You must continue execution to reenable function evaluation. string
    Evidence    Function evaluation disabled because a previous function evaluation timed out. You must continue execution to reenable function evaluation. System.Security.Policy.Evidence
    ExportedTypes   Function evaluation disabled because a previous function evaluation timed out. You must continue execution to reenable function evaluation. System.Collections.Generic.IEnumerable<System.Type>
    FullName    Function evaluation disabled because a previous function evaluation timed out. You must continue execution to reenable function evaluation. string
    GlobalAssemblyCache Function evaluation disabled because a previous function evaluation timed out. You must continue execution to reenable function evaluation. bool
    HostContext Function evaluation disabled because a previous function evaluation timed out. You must continue execution to reenable function evaluation. long
    ImageRuntimeVersion Function evaluation disabled because a previous function evaluation timed out. You must continue execution to reenable function evaluation. string
    IsDynamic   Function evaluation disabled because a previous function evaluation timed out. You must continue execution to reenable function evaluation. bool
    IsFullyTrusted  Function evaluation disabled because a previous function evaluation timed out. You must continue execution to reenable function evaluation. bool
    Location    Function evaluation disabled because a previous function evaluation timed out. You must continue execution to reenable function evaluation. string
    ManifestModule  Function evaluation disabled because a previous function evaluation timed out. You must continue execution to reenable function evaluation. System.Reflection.Module
    Modules Function evaluation disabled because a previous function evaluation timed out. You must continue execution to reenable function evaluation. System.Collections.Generic.IEnumerable<System.Reflection.Module>
    PermissionSet   Function evaluation disabled because a previous function evaluation timed out. You must continue execution to reenable function evaluation. System.Security.PermissionSet
    ReflectionOnly  Function evaluation disabled because a previous function evaluation timed out. You must continue execution to reenable function evaluation. bool
    SecurityRuleSet Function evaluation disabled because a previous function evaluation timed out. You must continue execution to reenable function evaluation. System.Security.SecurityRuleSet

1 个答案:

答案 0 :(得分:0)

这也困扰了我一次。我遇到的问题可能与您的问题相同,就是我在另一个环境中使用调试器运行的可执行文件。这导致文件被锁定。我可以将文件加载到仅反射的上下文中,但是当我尝试查询类型时,它会挂起。

所以,请确保:

  • 您没有使用正在加载的可执行文件打开进程
  • 您没有在其他位置加载可执行文件,可能是由调试程序暂停
  • 使用反射的程序具有足够的权限来访问文件

验证完毕后,尝试重新启动计算机并再次尝试。如果它有效,那就是资源获取问题。如果没有,请上传您的可执行文件,如果可以,我可以尝试重现该问题。