我使用实体框架,SQL Server 2000, Visual Studio 2008和企业库开发了一个应用程序。

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

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)

实体框架似乎有问题,任何线索如何修复它?


当前回答

一个对我有效的解决方案是删除bin/和obj/文件夹并重新构建解决方案。

更新:

或者你可以尝试在“解决方案资源管理器”中右键单击“解决方案”节点,然后单击“清洁解决方案”,然后单击“重建解决方案”(感谢Emre Guldogan)

其他回答

我在使用ASP时遇到了这个错误。NET 4 + SQL Server 2008 R2 +实体框架4应用程序。

它在我的开发机器(Windows Vista 64位)上工作得很好。然后,当部署到服务器(Windows server 2008 R2 SP1)时,它将一直工作到会话超时。因此,我们部署应用程序,一切看起来都很好,然后让它超过20分钟的会话超时,然后抛出这个错误。

为了解决这个问题,我使用Ken Cox博客上的代码来检索LoaderExceptions属性。

对于我的情况,缺失的DLL是Microsoft.ReportViewer.ProcessingObjectModel(版本10)。这个DLL需要安装在运行应用程序的机器的GAC中。您可以在微软下载站点上的Microsoft Report Viewer 2010 Redistributable Package中找到它。

这对我很管用。把它添加到你的web.config中

<system.web>
  <trust level="Full" />

我有一个。net 4.0, ASP。NET MVC 2.0,实体框架4.0 web应用程序开发在Visual Studio 2010。我遇到了同样的问题,它在一台Windows Server 2008 R2服务器上工作,但在另一台Windows Server 2008 R2服务器上不能工作,即使。net和ASP。NET MVC是一样的,抛出和你的一样的错误。

我听从了miko的建议,所以我在故障服务器上安装了Windows SDK v7.1 (x64),这样我就可以运行!dumpheap了。

事实证明,安装Windows SDK v7.1 (x64)解决了这个问题。任何缺失的依赖项都必须包含在SDK中。它可以从微软Windows SDK for Windows 7和。net Framework 4下载。

我在引用一个nuget包时遇到了这个问题,后来使用删除选项将它从我的项目中删除。在与这个问题斗争了几个小时后,我不得不清理垃圾箱文件夹。为了避免这种情况,建议使用nuget卸载不需要的包,而不是通常的删除

这个错误没有真正的灵丹妙药。关键是要有理解问题的所有信息。动态加载的程序集很可能缺少引用的程序集。该程序集需要位于应用程序的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.
}