System.TypeLoadException:无法加载类型' System.Reflection.RuntimeReflectionExtensions'来自程序集mscorlib

时间:2016-07-14 13:40:57

标签: c# .net entity-framework

每当我初始化Entities类的实例时,我都会收到此错误。但这完全在我的本地PC上运行。完整的例外情况如下。

System.TypeLoadException: Could not load type 'System.Reflection.RuntimeReflectionExtensions' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
   at System.Data.Entity.Utilities.TypeExtensions.GetStaticProperty(Type type, String name)
   at System.Data.Entity.Infrastructure.DependencyResolution.ProviderServicesFactory.GetInstance(Type providerType)
   at System.Data.Entity.Infrastructure.DependencyResolution.ProviderServicesFactory.GetInstance(String providerTypeName, String providerInvariantName)
   at System.Data.Entity.Internal.AppConfig.<.ctor>b__2(ProviderElement e)
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at System.Data.Entity.Internal.AppConfig.<.ctor>b__1()
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.LazyInitValue()
   at System.Lazy`1.get_Value()
   at System.Data.Entity.Internal.AppConfig.get_DbProviderServices()
   at System.Data.Entity.Infrastructure.DependencyResolution.AppConfigDependencyResolver.RegisterDbProviderServices()
   at System.Data.Entity.Infrastructure.DependencyResolution.AppConfigDependencyResolver.GetServiceFactory(Type type, String name)
   at System.Data.Entity.Infrastructure.DependencyResolution.AppConfigDependencyResolver.<>c__DisplayClass1.<GetService>b__0(Tuple`2 t)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at System.Data.Entity.Infrastructure.DependencyResolution.AppConfigDependencyResolver.GetService(Type type, Object key)
   at System.Data.Entity.Infrastructure.DependencyResolution.ResolverChain.<>c__DisplayClass3.<GetService>b__0(IDbDependencyResolver r)
   at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
   at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
   at System.Data.Entity.Infrastructure.DependencyResolution.ResolverChain.GetService(Type type, Object key)
   at System.Data.Entity.Infrastructure.DependencyResolution.CompositeResolver`2.GetService(Type type, Object key)
   at System.Data.Entity.Infrastructure.DependencyResolution.DbDependencyResolverExtensions.GetService[T](IDbDependencyResolver resolver)
   at System.Data.Entity.DbContext.InitializeLazyInternalContext(IInternalConnection internalConnection, DbCompiledModel model)
   at System.Data.Entity.DbContext..ctor(String nameOrConnectionString)
   at testEF.Data.ERP_Model.ERP_entities..ctor() in c:\Users\Dilshan Jayaweera\Documents\Visual Studio 2013\Projects\testEF\testEF\Data\ERP_Model\ERP_entities.cs:line 10
   at testEF.Form1.timer1_Tick(Object sender, EventArgs e) in c:\Users\Dilshan Jayaweera\Documents\Visual Studio 2013\Projects\testEF\testEF\Form1.cs:line 23
   at System.Windows.Forms.Timer.OnTick(EventArgs e)
   at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

2 个答案:

答案 0 :(得分:1)

所以我做了自己的研究,发现了this post。根据这一点,我猜测类RuntimeReflectionExtensions也从.NET 4.5中的System.Core转移到mscorlib,因为我还针对.NET 4.5,我将它改回.NET 4.0,猜测什么?它解决了这个问题!

答案 1 :(得分:0)

您使用的是使用.net高于4.0创建的库吗?检查您的目标框架,并确保您只使用该版本的类。