【问题标题】:Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information. with EntityDataSource无法加载一种或多种请求的类型。检索 LoaderExceptions 属性以获取更多信息。与 EntityDataSource
【发布时间】:2011-04-18 08:15:33
【问题描述】:

我有一个问题,仅显示 ASP.NET (*.aspx) 页面上是否存在 EntityDataSource。当我刷新页面 (F5) 或再次查看它时会发生有趣的事情,这让我发疯,这似乎是 Entity Framework 的错误,因为我在另一个项目中尝试过,我得到同样的错误。

无法加载一种或多种请求的类型。检索 LoaderExceptions 属性以获取更多信息。 说明:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。 异常详细信息:System.Reflection.ReflectionTypeLoadException:无法加载一种或多种请求的类型。检索 LoaderExceptions 属性以获取更多信息。

堆栈跟踪:

[ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.]
   System.Reflection.RuntimeModule.GetTypes(RuntimeModule module) +0
   System.Reflection.RuntimeModule.GetTypes() +4
   System.Reflection.Assembly.GetTypes() +78
   System.Data.Metadata.Edm.ObjectItemConventionAssemblyLoader.LoadTypesFromAssembly() +32
   System.Data.Metadata.Edm.ObjectItemAssemblyLoader.Load() +25
   System.Data.Metadata.Edm.AssemblyCache.LoadAssembly(Assembly assembly, Boolean loadReferencedAssemblies, ObjectItemLoadingSessionData loadingData) +160
   System.Data.Metadata.Edm.AssemblyCache.LoadAssembly(Assembly assembly, Boolean loadReferencedAssemblies, KnownAssembliesSet knownAssemblies, EdmItemCollection edmItemCollection, Action`1 logLoadMessage, Object& loaderCookie, Dictionary`2& typesInLoading, List`1& errors) +166
   System.Data.Metadata.Edm.ObjectItemCollection.LoadAssemblyFromCache(ObjectItemCollection objectItemCollection, Assembly assembly, Boolean loadReferencedAssemblies, EdmItemCollection edmItemCollection, Action`1 logLoadMessage) +316
   System.Data.Metadata.Edm.ObjectItemCollection.ExplicitLoadFromAssembly(Assembly assembly, EdmItemCollection edmItemCollection, Action`1 logLoadMessage) +53
   System.Data.Metadata.Edm.MetadataWorkspace.ExplicitLoadFromAssembly(Assembly assembly, ObjectItemCollection collection, Action`1 logLoadMessage) +93
   System.Data.Metadata.Edm.MetadataWorkspace.LoadFromAssembly(Assembly assembly, Action`1 logLoadMessage) +130
   System.Web.UI.WebControls.EntityDataSourceView.ConstructContext() +585
   System.Web.UI.WebControls.EntityDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +76
   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +21
   System.Web.UI.WebControls.DataBoundControl.PerformSelect() +143
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +74
   System.Web.UI.WebControls.GridView.DataBind() +4
   System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +66
   System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +75
   System.Web.UI.Control.EnsureChildControls() +102
   System.Web.UI.Control.PreRenderRecursiveInternal() +42
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2496

我该如何解决这个问题?

【问题讨论】:

    标签: c# .net entity-framework exception-handling entitydatasource


    【解决方案1】:

    这是 .NET 4.0 中的一个错误,应该在 .NET 4.5 中修复。一种可能的解决方案是在您的引用上将“复制本地”设置为 true 并删除不需要的引用。

    更多信息在Unable to load one or more of the requested types. Connected with EntityDataSource

    【讨论】:

    • 我使用 .NET 4.5,遇到了同样的问题。您的 CopyLocal 建议有效
    【解决方案2】:

    请参阅问题 Random 'Unable to load one or more of the requested types' Errors (588847):

    EntityDataSource 将尝试从所有引用的程序集中加载所有类型,以发现您的实体数据模型的所有实体类型。

    使用其他答案的技术确保所有 DLL 文件都设置为“复制本地”可能会有所帮助。否则,请尝试他们的解决方法:将 EntityDataSourceContextTypeName 属性设置为实体容器类型的完全限定名称。

    解决方法就是为我解决了这个问题。

    【讨论】:

    • 谢谢你 - 终于解决了我的问题!
    【解决方案3】:

    我遇到了同样的问题,发现这是因为生产环境缺少正确的 DLL。您可以将项目引用的 Copy Local 属性设置为 true。

    有关详细信息,请参阅 Error message 'Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.'

    【讨论】:

      【解决方案4】:

      我今天遇到了同样的问题,但只是在生产服务器上,而不是在开发或测试中(图)。我仍在调查发生了什么,但我将生产服务器 .NET Trust Level 更改为 High 并且问题消失了......这显然是一个临时修复,但总比没有好。我希望这会有所帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-08-23
        • 1970-01-01
        • 2010-11-08
        • 2016-10-03
        • 1970-01-01
        相关资源
        最近更新 更多