C# 无法在新域中获取类型()

C# 无法在新域中获取类型(),c#,C#,我已经创建了一个新域,然后将程序集加载到此域中,但是当GetTypes()出现如所附图片所示的错误时,希望大家能够帮助,谢谢。 代码 错误 是否已检查BeyConsRevitProject.dll程序集是否位于应用程序的bin目录中?这是一个可能的原因。尝试删除bin/和obj/文件夹并重建解决方案,如果错误仍然存在,请使用以下代码确定错误的真正原因: using System.IO; using System.Reflection; using System.Text; try {

我已经创建了一个新域,然后将程序集加载到此域中,但是当GetTypes()出现如所附图片所示的错误时,希望大家能够帮助,谢谢。 代码

错误


是否已检查BeyConsRevitProject.dll程序集是否位于应用程序的bin目录中?这是一个可能的原因。尝试删除bin/和obj/文件夹并重建解决方案,如果错误仍然存在,请使用以下代码确定错误的真正原因:

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.
}
本·格里普卡在这里提出了这一准则:

我删除了bin目录,并按照您的指示使用try catch重新构建了它,但它没有跳转到catch中。下图这是因为现在正在引发另一个异常,而此异常不是来自ReflectionTypeLoadException类型。但是通过这个新的异常,我们可以确认程序集确实缺少引用。检查项目依赖项上的BeyConsRevitProject,并编写其正确路径,或者在项目My project的任何位置未引用它时将其添加为依赖项。csproj:此dll是否确实位于本地计算机的此路径中?D:\Github\BeyConsPlugin\BeyConsProject\bin\x64\Debug\beyconrevitproject.dlys,所有的dll都在那里D:\Github\BeyConsPlugin\BeyConsProject\bin\x64\Debug为什么一直发布基本相同的问题?正如我在你的问题中提到的,你正在使用的代码有多个问题。此外,我发现您没有使用我在我的报告中建议的解决途径,您所说的解决途径使您的问题“未解决”
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.
}