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

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


当前回答

另一个解决方案,知道为什么什么都不能工作(从微软连接):

将以下代码添加到项目中: foreach (AppDomain.CurrentDomain.GetAssemblies()中的var asm) { asm.GetTypes (); } 关闭生成序列化程序集。 构建并执行。

其他回答

点击“查看异常详细信息”检查此属性:

我有一个。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包… 合并包并将包升级为相同的版本。

在Nuget控制台中输入迁移命令时,我遇到了实体框架的这个问题。

当我把我的OAuthAuthorizationServerProvider代码从我的应用程序移动到一个包含核心数据访问逻辑以及我的DBContext类的类库项目时,问题就出现了。

我检查类库项目引用的所有dll。对于所有这些(除了.net系统dll) CopyToLocal是真的,我完全困惑。

I knew that there was something wrong with DLLs themselves not my codes. I checked them again and I noticed that when I moved my ApplicationOauthProvider class into a class library project the ApplicationOauthProvider inherits from OAuthAuthorizationServerProvider class which is located in Microsoft.Owin.Security.OAuth assembly, I checked it's package version and suddenly noticed that the version of package that I used for the class library project (not my application project) is very old 2.1, but on my application the latest version was installed (3.0.1) so I upgraded version of the Microsoft.Owin.Security.OAuth package from Nuget fo my class library project and problem got away

简而言之,在检查dll的copytollocal属性后,也检查它们的版本,并将旧版本更新到最新版本