C# 为什么查询程序集';s类型通过反射导致程序在调试时意外挂起?

C# 为什么查询程序集';s类型通过反射导致程序在调试时意外挂起?,c#,.net,reflection,.net-assembly,C#,.net,Reflection,.net Assembly,使用此代码将停止响应我的程序 Assembly assembly = Assembly.LoadFrom(@"C:\test\test.exe"); Type[] typesInAssembly = assembly.GetTypes(); 在调试模式下,当第二行执行时,此代码停止响应 我将test.exe更改为空的WindowsformApplication.exe,它可以正常工作。 我不知道为什么它不能使用test.exe。 我在调试局部变量部分中放置了断点并检查了局部变量,在那个里我看到

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

Assembly assembly = Assembly.LoadFrom(@"C:\test\test.exe");
Type[] typesInAssembly = assembly.GetTypes();
在调试模式下,当第二行执行时,此代码停止响应

我将
test.exe
更改为空的WindowsformApplication.exe,它可以正常工作。 我不知道为什么它不能使用
test.exe
。 我在调试局部变量部分中放置了断点并检查了局部变量,在那个里我看到了一些错误图标,我将它们粘贴在下面。我希望有人能帮我

    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
DefinedTypes函数计算超时。System.Collections.Generic.IEnumerable
入口点函数计算已禁用,因为以前的函数计算超时。必须继续执行才能重新启用函数求值。System.Reflection.MethodInfo
EscapedCodeBase函数计算已禁用,因为上一个函数计算超时。必须继续执行才能重新启用函数求值。一串
证据功能评估已禁用,因为以前的功能评估超时。必须继续执行才能重新启用函数求值。系统、安全、政策、证据
ExportedTypes函数计算已禁用,因为以前的函数计算超时。必须继续执行才能重新启用函数求值。System.Collections.Generic.IEnumerable
已禁用全名函数求值,因为上一个函数求值超时。必须继续执行才能重新启用函数求值。一串
GlobalAssemblyCache函数求值已禁用,因为以前的函数求值超时。必须继续执行才能重新启用函数求值。布尔
HostContext函数计算已禁用,因为以前的函数计算超时。必须继续执行才能重新启用函数求值。长的
ImageRuntimeVersion函数计算已禁用,因为以前的函数计算超时。必须继续执行才能重新启用函数求值。一串
IsDynamic功能评估已禁用,因为以前的功能评估超时。必须继续执行才能重新启用函数求值。布尔
IsFullyTrusted函数求值已禁用,因为以前的函数求值超时。必须继续执行才能重新启用函数求值。布尔
由于先前的功能评估超时,位置功能评估已禁用。必须继续执行才能重新启用函数求值。一串
ManifestModule功能评估已禁用,因为以前的功能评估超时。必须继续执行才能重新启用函数求值。系统反射模块
模块功能评估已禁用,因为以前的功能评估超时。必须继续执行才能重新启用函数求值。System.Collections.Generic.IEnumerable
PermissionSet函数评估已禁用,因为以前的函数评估超时。必须继续执行才能重新启用函数求值。System.Security.PermissionSet
ReflectionOnly函数求值已禁用,因为以前的函数求值超时。必须继续执行才能重新启用函数求值。布尔
SecurityRuleSet函数计算已禁用,因为以前的函数计算超时。必须继续执行才能重新启用函数求值。System.Security.SecurityRuleSet

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

因此,请确保:

  • 您没有打开正在加载的可执行文件的进程
  • 您没有在别处加载可执行文件,可能是被调试器暂停的
  • 使用反射的程序有足够的权限访问该文件

验证这些内容后,请尝试重新启动计算机并重试。如果它起作用,那就是一个资源获取问题。如果没有,请上载可执行文件(如果可以),我可以尝试重现该问题。

在调试选项中,“常规”部分取消选中“启用属性求值”和其他隐式函数调用解决了此消息,但在编译代码后,我为程序集设置了断点,并检入了局部变量,用户关闭了隐式函数求值。我可以在那里评估。例如入口点。但我无法评估该部分中定义的类型。当我尝试评估时,它显示了相同的信息