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

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


当前回答

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

这解决了我的问题……

其他回答

在我的情况下,我有一个nuget包,安装在我的项目,但包文件夹从未检入到TFS,因此,在构建机器的nuget包bin文件丢失。因此在生产中我得到了这个错误。我不得不比较bin文件夹在生产和我的本地,然后我发现哪些dll是缺失的,我发现那些属于一个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属性后,也检查它们的版本,并将旧版本更新到最新版本

在配置管理器中验证每个项目是否正确设置。

类似于William Edmondson关于这个问题的原因,我将我的配置管理器设置从“调试”“任意CPU”切换到“调试”“。net”。问题是“。”NET的版本没有配置为构建所有的项目,所以我的一些dll是过时的(而另一些是最新的)。这导致启动应用程序时出现许多问题。

临时解决方案是执行Kenny Eliasson的建议,清除\bin和\obj目录。然而,一旦我对非编译项目做了更多的更改,一切都会再次失败。

我改变了引用的特定版本属性为假,这有助于。

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

这解决了我的问题……