... or one of its dependencies. The system cannot find the file specified... 加载指定dll失败

来源:互联网 发布:雪豹特种部队 知乎 编辑:程序博客网 时间:2024/04/30 20:55

我们在写代码的时候偶尔会遇到下面的问题。

... or one of its dependencies. The system cannot find the file specified... 这类问题主要是告诉用户当前的dll找不到或者是缺少相应的引用。大家不妨加上下面的catch语句试下。我们看下errorMessage后就知道问题出在哪里了。

using System.IO;using System.Reflection;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);        if (exSub is FileNotFoundException)        {            FileNotFoundException exFileNotFound = exSub as FileNotFoundException;            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.}

原创粉丝点击