首页 文章

实体框架LoaderExceptions无法加载一个或多个请求的类型

提问于
浏览
3

我有一个使用实体框架的Web服务 . 释放到测试环境时,我收到以下错误:

“无法加载一个或多个请求的类型 . ” - 下面的堆栈跟踪......

测试盒安装了.NET 3.5 SP 1,我在这里阅读了上一篇文章:

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

然而,在我的情况下,答案并没有解决它 . 我已经将我的开发机器上的工作副本复制并粘贴到测试盒上,以确保调试DLL没有问题(如答案所示),但没有运气 .

这是一个已知的问题?我花了一整个上午试图调试这个!!如果有人知道解决方案,请告诉我!

Retrieve the LoaderExceptions property for more information.   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, Dictionary`2 knownAssemblies, Dictionary`2& 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)
   at Company.Domain.ICommuicationsEntities.CreateQuery[T](String queryString, ObjectParameter[] parameters)
   at Comany.EntityFrameworkRepository`1.GetQuery()
   at Comany.Repositories.EntityFrameworkRepository`1.GetFiltered(Expression`1 filter, IncludeBuilder`1 includeBuilder)
   at Comany.Repositories.EntityFrameworkRepository`1.GetFiltered(Expression`1 filter)

3 回答

  • 1

    正如堆栈的顶线所示:

    检索LoaderExceptions属性以获取更多信息 .

    您可以通过检查调试器中的异常来找到它 .

  • 0

    堆栈跟踪“检索LoaderExceptions属性以获取更多信息”的第一行绝对是关键 . 您需要捕获ReflectionTypeLoadException或转换您的常规异常 .

    catch (System.Reflection.ReflectionTypeLoadException ex) {
        ex.LoaderExceptions;
    } catch (Exception ex) {
        if (ex is System.Reflection.ReflectionTypeLoadException)
            ((System.Reflection.ReflectionTypeLoadException)ex).LoaderExceptions;
    }
    

    然后,您可以检查LoaderExceptions属性以找出可能缺少的DLL引用 .

  • 3

    System.IO.FileNotFoundException:无法加载文件或程序集'System.Web.Mvc,Version = 3.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'或其依赖项之一 . 该系统找不到指定的文件 . 文件名:'System.Web.Mvc,Version = 3.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'WNN:程序集绑定日志记录已关闭 . 要启用程序集绑定失败日志记录,请将注册表值[HKLM \ Software \ Microsoft \ Fusion!EnableLog](DWORD)设置为1 .

    注意:程序集绑定失败日志记录会导致一些性能损失 . 要关闭此功能,请删除注册表值 [HKLM\Software\Microsoft\Fusion!EnableLog] .

相关问题