mscorlib.dll中出现“System.Reflection.TargetInvocationException”类型的异常,但未在用户代码中处理

时间:2015-02-27 16:57:50

标签: c# sql-server-2008-r2 entity-framework-4

类型' System.Reflection.TargetInvocationException'的异常发生在mscorlib.dll中但未在用户代码中处理

附加信息:调用目标引发了异常。

public ApplicationDbContext()             :base(" DefaultConnection",throwIfV1Schema:false) 这是我的代码,其中异常在运行时显示。 我使用.net framework 4.5和sqlserver2008r2。 所以任何人都可以帮助我摆脱这个问题。

堆栈追踪:

[TypeLoadException:无法加载类型' System.Data.Entity.Infrastructure.TableExistenceChecker'来自assembly' EntityFramework,Version = 6.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089'。]    System.Data.Entity.SqlServerCompact.Legacy.SqlCeProviderServices..ctor()+ 0    System.Data.Entity.SqlServerCompact.Legacy.SqlCeProviderServices..cctor()+44

[TypeInitializationException:&System; System.Data.Entity.SqlServerCompact.Legacy.SqlCeProviderServices'的类型初始值设定项。抛出异常。]

[TargetInvocationException:调用目标抛出了异常。]    System.RuntimeFieldHandle.GetValue(RtFieldInfo字段,Object实例,RuntimeType字段类型,RuntimeType declaringType,Boolean&amp; domainInitialized)+0    System.Reflection.RtFieldInfo.UnsafeGetValue(Object obj)+124    System.Reflection.RtFieldInfo.InternalGetValue(Object obj,StackCrawlMark&amp; stackMark)+132    System.Reflection.RtFieldInfo.GetValue(Object obj)+21    System.Data.Entity.Utilities.MemberInfoExtensions.GetValue(MemberInfo memberInfo)+132    System.Data.Entity.Infrastructure.DependencyResolution.ProviderServicesFactory.GetInstance(Type providerType)+194    System.Data.Entity.Infrastructure.DependencyResolution.ProviderServicesFactory.GetInstance(String providerTypeName,String providerInvariantName)+142    System.Data.Entity.Internal.AppConfig。&lt; .ctor&gt; b__2(ProviderElement e)+109    System.Linq.WhereSelectEnumerableIterator 2.MoveNext() +145 System.Collections.Generic.List 1..ctor(IEnumerable 1 collection) +460 System.Linq.Enumerable.ToList(IEnumerable 1 source)+58    System.Data.Entity.Internal.AppConfig。&lt; .ctor&gt; b__1()+135    System.Lazy 1.CreateValue() +415 System.Lazy 1.LazyInitValue()+152    System.Lazy 1.get_Value() +75 System.Data.Entity.Internal.AppConfig.get_DbProviderServices() +40 System.Data.Entity.Infrastructure.DependencyResolution.AppConfigDependencyResolver.RegisterDbProviderServices() +59 System.Data.Entity.Infrastructure.DependencyResolution.AppConfigDependencyResolver.GetServiceFactory(Type type, String name) +126 System.Data.Entity.Infrastructure.DependencyResolution.<>c__DisplayClass1.<GetService>b__0(Tuple 2 t)+110    System.Collections.Concurrent.ConcurrentDictionary 2.GetOrAdd(TKey key, Func 2 valueFactory)+72    System.Data.Entity.Infrastructure.DependencyResolution.AppConfigDependencyResolver.GetService(Type type,Object key)+210    System.Data.Entity.Infrastructure.DependencyResolution。&lt;&gt; c__DisplayClass3.b__0(IDbDependencyResolver r)+60    System.Linq.WhereSelectArrayIterator 2.MoveNext() +66 System.Linq.Enumerable.FirstOrDefault(IEnumerable 1 source,Func 2 predicate) +94 System.Data.Entity.Infrastructure.DependencyResolution.ResolverChain.GetService(Type type, Object key) +250 System.Data.Entity.Infrastructure.DependencyResolution.CompositeResolver 2.GetService(Type type,Object key)+63    System.Data.Entity.Infrastructure.DependencyResolution.DbDependencyResolverExtensions.GetService(IDbDependencyResolver resolver)+141    System.Data.Entity.DbContext.InitializeLazyInternalContext(IInternalConnection internalConnection,DbCompiledModel model)+124    System.Data.Entity.DbContext..ctor(String nameOrConnectionString)+103    Microsoft.AspNet.Identity.EntityFramework.IdentityDbContext 6..ctor(String nameOrConnectionString) +37 Microsoft.AspNet.Identity.EntityFramework.IdentityDbContext 1..ctor(String nameOrConnectionString,Boolean throwIfV1Schema)+45    Srismiles.Models.ApplicationDbContext..ctor()在f:\ Srismiles \ Srismiles \ Srismiles \ Models \ IdentityModels.cs:32    fris中的Srismiles.Logic.RoleActions.AddUserAndRole():Srismiles \ Srismiles \ Srismiles \ Logic \ RoleActions.cs:17    Srismiles.Global.Application_Start(Object sender,EventArgs e)在f:\ Srismiles \ Srismiles \ Srismiles \ Global.asax.cs:29

[HttpException(0x80004005):调用目标抛出了异常。]    System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context,HttpApplication app)+9935033    System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext,HttpContext context,MethodInfo [] handlers)+118    System.Web.HttpApplication.InitSpecial(HttpApplicationState状态,MethodInfo []处理程序,IntPtr appContext,HttpContext上下文)+172    System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext,HttpContext context)+336    System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext)+296

[HttpException(0x80004005):调用目标抛出了异常。]    System.Web.HttpRuntime.FirstRequestInit(HttpContext context)+9913572    System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context)+101    System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr,HttpContext context)+254

1 个答案:

答案 0 :(得分:-2)

你一定要尝试做两件事:

  • 将EF软件包更新为所有项目中的最新版本( Update-Package EntityFramework 将在软件包控制台中为您提供服务)
  • 在数据库中包含数据上下文的所有项目中使用 Update-Database 命令

我现在遇到了同样的问题,通过这些步骤解决了这个问题。