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

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


当前回答

我在引用一个nuget包时遇到了这个问题,后来使用删除选项将它从我的项目中删除。在与这个问题斗争了几个小时后,我不得不清理垃圾箱文件夹。为了避免这种情况,建议使用nuget卸载不需要的包,而不是通常的删除

其他回答

当我在其中一个项目上安装NuGet包而忘记更新另一个项目时,我遇到了这个问题。

我通过使两个项目具有相同的参考程序集来解决这个问题。

我在编译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对我来说已经足够好了。:)

我希望这对你们有帮助。

我为SharePoint构建了一些项目,当然,也部署了它们。有一次发生了。

我在C:\Windows\assembly\temp\xxx(使用FarManager)中找到了一个旧的程序集,在重新启动后删除了它,并构建了所有项目。

我对MSBuild有疑问,因为在项目程序集中链接的项目和每个程序集都标记为“复制本地”,但不是从GAC。

当我试图用包管理器控制台添加实体框架迁移时,我也有同样的问题(但在我的本地)。

我解决这个问题的方法是创建一个控制台应用程序,其中Main()有以下代码:

 var dbConfig = new Configuration();
 var dbMigrator = new DbMigrator(dbConfig);
 dbMigrator.Update();

确保Configuration类是失败项目的迁移配置。你需要System.Data.Entity.Migrations来使用DbMigrator。

在应用程序中设置断点,并运行它。异常应该由Visual Studio捕获(除非您将异常类型设置为不中断调试会话),并且您应该能够找到您正在寻找的信息。

在我的案例中,缺少的引用是EFProviderWrapperToolkit。

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

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