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

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


当前回答

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

其他回答

我正在通过FTP更新一个网站。我假设网站正在使用中,当尝试更新bin文件夹时,几个DLL文件必须被锁定并且没有更新。

在那里,我看到了错误500页,并将customErrors模式设置为关闭,看到了OP提到的错误消息。

问题是我没有看到FTP程序中列出的失败。我重试了那些失败的失败,他们上传。更新了最后一个DLL文件。于是这个网站就成功了。

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

!dumpheap -stat -type异常/D

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

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

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

这解决了我的问题……

在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属性后,也检查它们的版本,并将旧版本更新到最新版本

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