处理办法

catch ReflectionTypeLoadException ,然后从里面读取 Types 数据(成功加载的类型)就可以了。

参考

ReflectionTypeLoadException Class (System.Reflection) | Microsoft Docs

.net - How to prevent ReflectionTypeLoadException when calling Assembly.GetTypes() - Stack Overflow

代码封装


class AssemblyTypesDetector
{
public Assembly Assembly { get; } public Exception Exception { get; private set; } public AssemblyTypesDetector(Assembly assembly)
{
Assembly = assembly;
} public AssemblyTypesDetector(string filePath)
{
Assembly = Assembly.LoadFile(filePath);
} public AssemblyTypesDetector(AssemblyName assemblyName)
{
Assembly = Assembly.Load(assemblyName);
} public IList<Type> DetectTypes()
{
Type[] types = null;
try
{
types = Assembly.GetTypes().ToArray();
}
catch (ReflectionTypeLoadException reflectionTypeLoadException)
{
types = reflectionTypeLoadException.Types.Where(t => t != null).ToArray();
}
catch (Exception ex)
{
Exception = ex;
} return types?.ToList() ?? new List<Type>();
} public IList<Type> DetectTypes(Predicate<Type> predicate)
{
return DetectTypes().Where(predicate.Invoke).ToList();
} }

原文链接:

https://www.cnblogs.com/jasongrass/p/11990633.html

从程序集加载类型,遇到 ReflectionTypeLoadException 的处理办法的更多相关文章

  1. 未能加载文件或程序集 system.Web.Http.WebHost解决办法。

    在csdn中找到一个方法: Update-Package Microsoft.AspNet.WebApi -reinstall 然后就好了. 另外一个方法是缺少哪个dll,就复制一个dll放到bin文 ...

  2. 一次修改闭源 Entity Provider 程序集以兼容新 EntityFramework 的过程

    读完本文你会知道,如何在没有源码的情况下,直接修改一个 DLL 以去除 DLL 上的强命名限制,并在该程序集上直接添加你的“友元程序集(一种特殊的 Attribute,将它应用在程序集上,使得程序集内 ...

  3. 【ASP.NET MVC】"[A]System.Web.WebPages.Razor.Configuration.HostSection 无法强制转换为 ..."的解决办法

    1.错误页面: “/”应用程序中的服务器错误. [A]System.Web.WebPages.Razor.Configuration.HostSection 无法强制转换为 [B]System.Web ...

  4. C# 引用的程序集没有强名称

    首先查一下什么是强名称程序集,见百度百科帖子:http://baike.baidu.com/view/1145682.htm简单来说,就是为了解决Windows Dll Hell问题的,即不同公司开发 ...

  5. C# Winform 未能加载文件或程序集"System.Data.SQLite"或它的某一个依赖项。试图加载格式不正确的程序

    在使用Winform 开发了一个小软件,其中使用了SQLite作为数据库 但在我的Win7 64位系统上却出现了以下错误: System.BadImageFormatException: 未能加载文件 ...

  6. 2019-1-17 前言 C#高级编程(第11版)

    C#已更新为更快的速度.主要版本7.0是2017年3月发布,次要版本7.1和7.2很快发布在2017年8月和2017年12月.通过项目设置,您可以与每个应用程序一起分发,是开源的,不可用仅适用于Win ...

  7. c# dll问题

    问题描述: dll完全拷贝另一个程序,可是报缺少引用程序集之类的错误. 解决办法: 有可能是.net版本造成的错误.一般常见在3.5升到4之后,存在很多容差.

  8. 关于 RuntimeBinderException 异常

    Microsoft.CSharp.RuntimeBinder.RuntimeBinderException的异常一般来自于两种: 第一种情况: Predefined type 'Microsoft.C ...

  9. 配置IIS提示打开目录浏览时的问题:未能从程序集“System.ServiceModel, Version=3.0.0.0”中加载类型“System.ServiceModel.Activation.HttpModule” 的解决办法

    错误消息: 未能从程序集“System.ServiceModel, Version=3.0.0.0”中加载类型“System.ServiceModel.Activation.HttpModule” 的 ...

随机推荐

  1. 手把手教你搭建织女星开发板RISC-V开发环境

    前言 Windows环境下搭建基于Eclipse + RISC-V gcc编译器的RISC-V开发环境,配合openocd调试软件,可以实现RISC-V内核程序的编译.下载和调试. 准备工作 工欲善其 ...

  2. 在ASP.NET中备份数据库以及还原(不成熟)

    using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...

  3. C# 调用POST请求

    public static void PostUrl_Ex(string url, string postData) { try { //对于提交内容中的中文使用UrlEncode方式编码 发送 // ...

  4. javaWeb技术第一篇之HTML

    <!-- 当前是最简的html --> <html> <!-- 告诉浏览器当前是一个html文档 最外面的标签. --> <head> <!--h ...

  5. 设计好的报表是如何在 web 上显示的

    润乾报表主要用来开发在 java web 端呈现的报表工具,设计器为桌面版,那么开发后的报表如何发布到 web 端是用户较为关心的问题. 润乾报表 web 端发布,采用 Taglib 方式,只需要在 ...

  6. 转战物联网·基础篇06-深入理解MQTT协议之基本术语

      通过上一节我们对MQTT协议已经有了初步的印象,这一节我们开始深入的理解一下MQTT协议,介绍常用的MQTT 3.1.1版本,5.0版本后面指介绍新增部分即可.这一节我们先介绍MQTT里常用的术语 ...

  7. Attaching an entity of type 'xxx' failed because another entity of the same type already has the same primary key value.

    问题的详细描述: Attaching an entity of type 'xxxxx' failed because another entity of the same type already ...

  8. 2-2 远程管理命令-网卡和IP地址的概念

    02.查看或配置网卡信息 序号 命令 对应英文 作用 01 ifconfig configure a network interface 查看/配置计算机当前的网卡配置信息 02 ping ip地址 ...

  9. X短期项目总结

    刚退出了一个项目,简称为X项目.这个项目中,还是遇到了不少问题,也解决了部分问题,还是挺有收获的,所以总结一下. 虽然标题说是短期项目总结,但其实这个项目并不短, 持续了约3年时间. 所谓的短,只是我 ...

  10. 8. java 面向对象

    一.面向对象特征 1. 封装 方法就是一种封装 关键字private也是一种封装 封装就是讲一些逻辑细节信息隐藏起来,对于外界不可见:外界只需调用我即可: 一旦使用了private进行修饰,那么本类当 ...