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

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


当前回答

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

!dumpheap -stat -type异常/D

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

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

其他回答

一个对我有效的解决方案是删除bin/和obj/文件夹并重新构建解决方案。

更新:

或者你可以尝试在“解决方案资源管理器”中右键单击“解决方案”节点,然后单击“清洁解决方案”,然后单击“重建解决方案”(感谢Emre Guldogan)

正如之前所提到的,通常情况下,组装不存在。

要确切地知道您丢失了什么程序集,请附加调试器,设置断点,当您看到异常对象时,钻到'LoaderExceptions'属性。丢失的程序集应该在那里。

希望能有所帮助!

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

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

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

我能够通过在项目中所有引用的DLL文件上标记“复制本地=True”来修复这个问题,在测试服务器上重新构建和部署。

我在编译Visual Studio包(VSPackage)时报告了相同的错误消息。编译整个解决方案,当CreatePkgDef创建包时抛出错误。话虽如此,很明显,我无法捕获loaderexception,因为它不是我的应用程序抛出的,而是微软自己的工具。(虽然我对CreatePkgDef的混乱负责。)

在我的情况下,根本原因是我的解决方案创建了一个MyDll.dll,已经注册到GAC(他们是不同的),所以CreatePgkDef混淆了使用哪个,它决定只是抛出一个错误,这并没有真正的帮助。GAC中的MyDll.dll是由相同产品的安装程序注册的(显然是较早的版本,内容略有不同)。

如何解决

Preferred way: Make sure you use the correct version of MyDll.dll When compiling your project make sure you use a different version number than you used in the previous version located in the GAC. Make sure the following attributes are correct: [assembly: AssemblyVersion("1.0.0.1")] // Assuming the old DLL file was versioned 1.0.0.0 [assembly: AssemblyFileVersion("1.0.0.1")] // Assuming the old DLL file was versioned 1.0.0.0 If needed, specify the fully qualified assembly name (for example, "MyDll.dll, Version=1.0.0.1, Culture=neutral, PublicKeyToken=1234567890abcdef") when you reference it in your other projects. If the above failed: You can uninstall the old MyDll.dll from GAC How to Uninstall an Assembly from the GAC Uninstall the application that includes MyDll.dll

更改AssemblyVersion对我来说已经足够好了。:)

我希望这对你们有帮助。