简体   繁体   中英

Exception on new ASP.NET MVC 4 project

I have created a new aspx MVC 4 project. I have created some new files on top of the default MVC 4 template. However, now, when I click the Register at the system I get an exception. I did not changed anything at the register, just added some views. The exception I get is shown below. Does anyone know how to fix this? Thanks a Lot,

John

System.Reflection.TargetInvocationException was unhandled by user code
  HResult=-2146232828
  Message=Exception has been thrown by the target of an invocation.
  Source=mscorlib
  StackTrace:
       at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
       at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
       at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
       at System.Activator.CreateInstance(Type type, Boolean nonPublic)
       at System.Activator.CreateInstance(Type type)
       at System.Threading.LazyHelpers`1.ActivatorFactorySelector()
       at System.Threading.LazyInitializer.EnsureInitializedCore[T](T& target, Boolean& initialized, Object& syncLock, Func`1 valueFactory)
       at System.Threading.LazyInitializer.EnsureInitialized[T](T& target, Boolean& initialized, Object& syncLock)
       at Project_Team5.Filters.InitializeSimpleMembershipAttribute.OnActionExecuting(ActionExecutingContext filterContext) in c:\Users\john_000\Documents\Visual Studio 2013\Projects\Project_Team5\Project_Team5\Filters\InitializeSimpleMembershipAttribute.cs:line 21
       at System.Web.Mvc.Async.AsyncControllerActionInvoker.InvokeActionMethodFilterAsynchronously(IActionFilter filter, ActionExecutingContext preContext, Func`1 nextInChain)
       at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass37.<>c__DisplayClass39.<>c__DisplayClass3b.<BeginInvokeActionMethodWithFilters>b__35()
       at System.Web.Mvc.Async.AsyncControllerActionInvoker.InvokeActionMethodFilterAsynchronously(IActionFilter filter, ActionExecutingContext preContext, Func`1 nextInChain)
  InnerException: System.InvalidOperationException
       HResult=-2146233079
       Message=The ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588
       Source=Project_Team5
       StackTrace:
            at Project_Team5.Filters.InitializeSimpleMembershipAttribute.SimpleMembershipInitializer..ctor() in c:\Users\john_000\Documents\Visual Studio 2013\Projects\Project_Team5\Project_Team5\Filters\InitializeSimpleMembershipAttribute.cs:line 45
       InnerException: System.InvalidOperationException
            HResult=-2146233079
            Message=The entity types 'CompanyType' and 'Company' cannot share table 'Company' because they are not in the same type hierarchy or do not have a valid one to one foreign key relationship with matching primary keys between them.
            Source=EntityFramework
            StackTrace:
                 at System.Data.Entity.ModelConfiguration.Configuration.Mapping.EntityMappingConfiguration.UpdateColumnNamesForTableSharing(DbDatabaseMapping databaseMapping, EdmEntityType entityType, DbTableMetadata toTable, DbEntityTypeMappingFragment fragment)
                 at System.Data.Entity.ModelConfiguration.Configuration.Mapping.EntityMappingConfiguration.FindOrCreateTargetTable(DbDatabaseMapping databaseMapping, DbEntityTypeMappingFragment fragment, EdmEntityType entityType, DbTableMetadata fromTable, Boolean isIdentityTable, Boolean& isTableSharing)
                 at System.Data.Entity.ModelConfiguration.Configuration.Mapping.EntityMappingConfiguration.Configure(DbDatabaseMapping databaseMapping, DbProviderManifest providerManifest, EdmEntityType entityType, DbEntityTypeMapping& entityTypeMapping, Boolean isMappingAnyInheritedProperty, Int32 configurationIndex, Int32 configurationCount)
                 at System.Data.Entity.ModelConfiguration.Configuration.Types.EntityTypeConfiguration.ConfigureTablesAndConditions(DbEntityTypeMapping entityTypeMapping, DbDatabaseMapping databaseMapping, DbProviderManifest providerManifest)
                 at System.Data.Entity.ModelConfiguration.Configuration.ModelConfiguration.ConfigureEntityTypes(DbDatabaseMapping databaseMapping, DbProviderManifest providerManifest)
                 at System.Data.Entity.ModelConfiguration.Configuration.ModelConfiguration.Configure(DbDatabaseMapping databaseMapping, DbProviderManifest providerManifest)
                 at System.Data.Entity.DbModelBuilder.Build(DbProviderManifest providerManifest, DbProviderInfo providerInfo)
                 at System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection)
                 at System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext)
                 at System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input)
                 at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
                 at System.Data.Entity.Internal.InternalContext.CreateObjectContextForDdlOps()
                 at System.Data.Entity.Database.Exists()
                 at Project_Team5.Filters.InitializeSimpleMembershipAttribute.SimpleMembershipInitializer..ctor() in c:\Users\john_000\Documents\Visual Studio 2013\Projects\Project_Team5\Project_Team5\Filters\InitializeSimpleMembershipAttribute.cs:line 34
            InnerException: 

I had the same problem. I resolved it by enabling and running my SQL Server service.

For me, I did the following as an admin on a windows 7 machine In start menu: type services > press enter > find SQL Server(SQLExpress) > right-click > click Properties > if start up type is disabled, switch to automatic or manual > Click Start

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM