我使用实体框架,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)
实体框架似乎有问题,任何线索如何修复它?
我在编译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对我来说已经足够好了。:)
我希望这对你们有帮助。
我在使用ASP时遇到了这个错误。NET 4 + SQL Server 2008 R2 +实体框架4应用程序。
它在我的开发机器(Windows Vista 64位)上工作得很好。然后,当部署到服务器(Windows server 2008 R2 SP1)时,它将一直工作到会话超时。因此,我们部署应用程序,一切看起来都很好,然后让它超过20分钟的会话超时,然后抛出这个错误。
为了解决这个问题,我使用Ken Cox博客上的代码来检索LoaderExceptions属性。
对于我的情况,缺失的DLL是Microsoft.ReportViewer.ProcessingObjectModel(版本10)。这个DLL需要安装在运行应用程序的机器的GAC中。您可以在微软下载站点上的Microsoft Report Viewer 2010 Redistributable Package中找到它。
在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属性后,也检查它们的版本,并将旧版本更新到最新版本