我使用实体框架,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控制台中输入迁移命令时,我遇到了实体框架的这个问题。
当我把我的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属性后,也检查它们的版本,并将旧版本更新到最新版本
将我的特定问题/解决方案添加到此,因为这是此错误消息的第一个结果。在我的例子中,当我在IIS中第一个应用程序的文件夹中部署第二个应用程序时收到了这个错误。两者都定义了具有相同名称的连接字符串,导致子应用程序有冲突,并反过来生成这个(对我来说)不明显的错误消息。它通过添加:
<clear/>
在子web应用程序的连接字符串块中,阻止它继承web的连接字符串。配置文件在层次结构中更高,所以它看起来像:
<connectionStrings>
<clear/>
<add name="DbContext" connectionString="MySERVER" providerName="System.Data.SqlClient" />
</connectionStrings>
一个参考堆栈溢出问题,帮助一旦我确定什么是
子应用程序会从父应用程序web.config继承吗?