其他分享
首页 > 其他分享> > Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more i

Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more i

作者:互联网

通过添加如下的代码catch exception获取具体却是的库的名称:

using System.IO;
using System.Reflection;
using System.Text;

try
{
    //The code that causes the error goes 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.
}

标签:load,requested,exSub,exFileNotFound,AppendLine,System,using,sb,more
来源: https://www.cnblogs.com/csstudy/p/11584108.html