加载DLL时的C#异常.找不到解决方案
发布时间:2020-12-14 05:24:24 所属栏目:Windows 来源:网络整理
导读:我有一个问题,在运行时在C#中加载DLL. 以下代码: foreach (var f in Directory.EnumerateFiles(startFolder,"*.dll",SearchOption.AllDirectories)){ try { var assembly = Assembly.LoadFrom(f); var types = assembly.GetTypes(); //exception raised her
我有一个问题,在运行时在C#中加载DLL.
以下代码: foreach (var f in Directory.EnumerateFiles(startFolder,"*.dll",SearchOption.AllDirectories)) { try { var assembly = Assembly.LoadFrom(f); var types = assembly.GetTypes(); //exception raised here foreach (var type in types) { if (type.GetInterface("IPlayerFactory") != null) instances.Add((IPlayerFactory)Activator.CreateInstance(type)); } assembly = null; } catch (ReflectionTypeLoadException ex) { /* later,keep reading */} 异常说: An exception of type 'System.Reflection.ReflectionTypeLoadException' occurred in mscorlib.dll but was not handled in user code Additional information: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information. 我搜索了一下堆栈,找到了这个捕获器以寻找更多信息(来源:here) 捕获块: catch (ReflectionTypeLoadException ex) { StringBuilder sb = new StringBuilder(); foreach (Exception exSub in ex.LoaderExceptions) { sb.AppendLine(exSub.Message); FileNotFoundException exFileNotFound = exSub as FileNotFoundException; if (exFileNotFound != null) { if (!string.IsNullOrEmpty(exFileNotFound.FusionLog)) { sb.AppendLine("Fusion Log:"); sb.AppendLine(exFileNotFound.FusionLog); } } sb.AppendLine(); } string errorMessage = sb.ToString(); //Display or log the error based on your application. Console.WriteLine(sb); } 所以我设法提取: 'Battleships.Desktop.vshost.exe' (CLR v4.0.30319: Battleships.Desktop.vshost.exe): Loaded 'C:SomePathsome_dll.dll'. Cannot find or open the PDB file. A first chance exception of type 'System.Reflection.ReflectionTypeLoadException' occurred in mscorlib.dll 我尝试了一些解决方案,但没有任 解决方法
在调试模式下构建代码时,会创建两个文件,一个是类库,另一个是“debug database”.pdb文件.如果在调试模式下运行代码,请在反射代码的bin中包含pdb文件. 另一件事是在命令提示符下使用fuslogvw查看Fusion日志.它可能会给出任何未处理的运行时故障/依赖性.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 我应该使用哪种Windows ext3驱动程序?
- 在windows中为msysgit设置openssh端口
- winforms – 在XNA中使用system.windows.forms
- 创建Windows任务计划定时调用网页执行任务(通过Windows Pow
- 如何在Windows用户的RDP会话中查找支持,我在哪里启动支持会
- windows – 按名称批量文件到网络上的MASS ping计算机组,检
- 如何在Windows上使用Perl在命令行上处理通配符?
- windows-server-2008-r2 – “在RD会话主机服务器上使用强制
- windows – 使用SID从Active Directory检索用户详细信息
- Windows – Win32:如何将字符串转换为日期?
推荐文章
站长推荐
热点阅读