简体   繁体   English

新的ASP.NET MVC 4项目上的异常

[英]Exception on new ASP.NET MVC 4 project

I have created a new aspx MVC 4 project. 我创建了一个新的aspx MVC 4项目。 I have created some new files on top of the default MVC 4 template. 我已经在默认的MVC 4模板上创建了一些新文件。 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. 我通过启用和运行SQL Server服务来解决此问题。

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 对我而言,我在Windows 7计算机上以管理员身份执行以下操作:在开始菜单中:键入服务>按Enter>查找SQL Server(SQLExpress)>右键单击>单击属性>如果启动类型被禁用,则切换为自动或手册>单击开始

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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