c# - 错误消息 'Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.'

标签 c# entity-framework

我已经使用 Entity Framework 开发了一个应用程序、SQL Server 2000、Visual Studio 2008 和 Enterprise Library。

它在本地工作得很好,但是当我将项目部署到我们的测试环境时,出现以下错误:

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

Stack trace: at System.Reflection.Module._GetTypesInternal(StackCrawlMark& stackMark)

at System.Reflection.Assembly.GetTypes()

at System.Data.Metadata.Edm.ObjectItemCollection.AssemblyCacheEntry.LoadTypesFromAssembly(LoadingContext context)

at System.Data.Metadata.Edm.ObjectItemCollection.AssemblyCacheEntry.InternalLoadAssemblyFromCache(LoadingContext context)

at System.Data.Metadata.Edm.ObjectItemCollection.AssemblyCacheEntry.LoadAssemblyFromCache(Assembly assembly, Boolean loadReferencedAssemblies, Dictionary2 knownAssemblies, Dictionary2& typesInLoading, List`1& errors)

at System.Data.Metadata.Edm.ObjectItemCollection.LoadAssemblyFromCache(ObjectItemCollection objectItemCollection, Assembly assembly, Boolean loadReferencedAssemblies)

at System.Data.Metadata.Edm.ObjectItemCollection.LoadAssemblyForType(Type type)

at System.Data.Metadata.Edm.MetadataWorkspace.LoadAssemblyForType(Type type, Assembly callingAssembly)

at System.Data.Objects.ObjectContext.CreateQuery[T](String queryString, ObjectParameter[] parameters)

Entity Framework 似乎有问题,有什么解决办法吗?

最佳答案

此错误没有真正 Elixir 的答案。关键是要有所有的信息来理解问题。很可能动态加载的程序集缺少引用的程序集。该程序集需要位于应用程序的 bin 目录中。

使用此代码确定缺少的内容。

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.
}

关于c# - 错误消息 'Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1091853/

相关文章:

c# - 将类型传递给泛型类

c# - 日期时间如何工作以及如何在 Windows 窗体 ADO 实体中比较两个日期?

c# - 解析动态 JSON

entity-framework - 使用 Entity Framework Code First 将 Visual Studio 2013 项目转换为 2015 时出现 System.StackOverflowException 错误

.net - 代码首先 CTP4 : Table with no primary key?

c# , Entity Framework 存储过程

c# - 如何更改 DateTime/GetLastWriteTime 的格式?

c# - 将 appSetting 写入单独的 *.config 文件

c# - 文件管理

c# - Mono 中的 System.Data.Entity.Design.PluralizationServices 错误