我使用实体框架,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)

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


当前回答

最初我尝试了Fusion日志查看器,但没有帮助 所以我最终使用WinDbg与SOS扩展。

!dumpheap -stat -type异常/D

然后我检查了FileNotFoundExceptions。异常中的消息包含未加载的DLL的名称。

注意,/D会给你超链接的结果,所以点击FileNotFoundException摘要中的链接。这将显示一个例外列表。然后点击其中一个例外的链接。那将!dumpobject异常。然后,您应该能够单击异常对象中的Message链接,然后您将看到文本。

其他回答

如果您在项目中使用EntityDataSource,解决方案是Fix:“无法加载一个或多个请求类型”错误。您应该设置ContextTypeName="ProjectNameNameSpace。EntityContainerName”

这解决了我的问题……

如果部署到IIS,请确保允许在IIS上使用32位应用程序。您可以在当前应用程序池的设置上定义这一点。

还要检查在.csproj文件中是否没有<Private>True</Private>用于未加载的程序集

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

以防其他答案都帮不了你:

当我遇到这个问题时,原来我的Windows服务是为x64平台构建的,而我无意中运行了32位版本的InstallUtil.exe。因此,请确保您使用的InstallUtil版本适合您所构建的平台。