TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Abdulmajeed Alshari
NA
266
61.4k
Entity Framework code first. Can't add migration
Sep 10 2019 4:03 AM
when write
PM> add-migration createDatabase
appear this error message :
System.TypeInitializationException: The type initializer for 'System.Data.Entity.Migrations.DbMigrationsConfiguration`1' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception. ---> System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize ---> System.Configuration.ConfigurationErrorsException: Only one <configSections> element allowed per config file and if present must be the first child of the root <configuration> element. (C:\Users\Eng. Abdulmajeed\documents\visual studio 2015\Projects\Housing_System\Housing_System\tmp7E06.tmp line 10)
at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal)
at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors)
at System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors()
at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
--- End of inner exception stack trace ---
at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
at System.Configuration.ClientConfigurationSystem.PrepareClientConfigSystem(String sectionName)
at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
at System.Configuration.ConfigurationManager.get_ConnectionStrings()
at System.Data.Entity.Internal.AppConfig..ctor()
at System.Data.Entity.Internal.AppConfig..cctor()
--- End of inner exception stack trace ---
at System.Data.Entity.Infrastructure.DependencyResolution.DbConfigurationManager.EnsureLoadedForAssembly(Assembly assemblyHint, Type contextTypeHint)
at System.Data.Entity.Infrastructure.DependencyResolution.DbConfigurationManager.EnsureLoadedForContext(Type contextType)
at System.Data.Entity.Migrations.DbMigrationsConfiguration`1..cctor()
--- End of inner exception stack trace ---
at System.Data.Entity.Migrations.DbMigrationsConfiguration`1..ctor()
at Housing_System.Migrations.Configuration..ctor() in C:\Users\Eng. Abdulmajeed\documents\visual studio 2015\Projects\Housing_System\Housing_System\Migrations\Configuration.cs:line 10
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Data.Entity.Migrations.Utilities.MigrationsConfigurationFinder.FindMigrationsConfiguration(Type contextType, String configurationTypeName, Func`2 noType, Func`3 multipleTypes, Func`3 noTypeWithName, Func`3 multipleTypesWithName)
at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.FindConfiguration()
at System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.RunCore()
at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run()
The type initializer for 'System.Data.Entity.Migrations.DbMigrationsConfiguration`1' threw an exception.
web.config as the follow:
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?
LinkId
=
301880
--
>
<
configuration
>
<
connectionStrings
>
<
add
name
=
"DBConnection"
connectionString
=
"Data Source=.;Integrated Security=True;initial catalog=Housing_Database;"
providerName
=
"System.Data.SqlClient"
/>
</
connectionStrings
>
<
configSections
>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<
section
name
=
"entityFramework"
type
=
"System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission
=
"false"
/>
</
configSections
>
<
appSettings
>
<
add
key
=
"webpages:Version"
value
=
"3.0.0.0"
/>
<
add
key
=
"webpages:Enabled"
value
=
"false"
/>
<
add
key
=
"ClientValidationEnabled"
value
=
"true"
/>
<
add
key
=
"UnobtrusiveJavaScriptEnabled"
value
=
"true"
/>
</
appSettings
>
<
system.web
>
<
compilation
debug
=
"true"
targetFramework
=
"4.5.2"
/>
<
httpRuntime
/>
<
httpModules
>
<
add
name
=
"ApplicationInsightsWebTracking"
type
=
"Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"
/>
</
httpModules
>
<
pages
controlRenderingCompatibilityVersion
=
"4.0"
/>
</
system.web
>
<
runtime
>
<
assemblyBinding
xmlns
=
"urn:schemas-microsoft-com:asm.v1"
>
<
dependentAssembly
>
<
assemblyIdentity
name
=
"System.Web.Helpers"
publicKeyToken
=
"31bf3856ad364e35"
/>
<
bindingRedirect
oldVersion
=
"1.0.0.0-3.0.0.0"
newVersion
=
"3.0.0.0"
/>
</
dependentAssembly
>
<
dependentAssembly
>
<
assemblyIdentity
name
=
"System.Web.WebPages"
publicKeyToken
=
"31bf3856ad364e35"
/>
<
bindingRedirect
oldVersion
=
"1.0.0.0-3.0.0.0"
newVersion
=
"3.0.0.0"
/>
</
dependentAssembly
>
<
dependentAssembly
>
<
assemblyIdentity
name
=
"System.Web.Mvc"
publicKeyToken
=
"31bf3856ad364e35"
/>
<
bindingRedirect
oldVersion
=
"1.0.0.0-5.2.3.0"
newVersion
=
"5.2.3.0"
/>
</
dependentAssembly
>
<
dependentAssembly
>
<
assemblyIdentity
name
=
"Newtonsoft.Json"
publicKeyToken
=
"30ad4fe6b2a6aeed"
culture
=
"neutral"
/>
<
bindingRedirect
oldVersion
=
"0.0.0.0-6.0.0.0"
newVersion
=
"6.0.0.0"
/>
</
dependentAssembly
>
<
dependentAssembly
>
<
assemblyIdentity
name
=
"WebGrease"
publicKeyToken
=
"31bf3856ad364e35"
culture
=
"neutral"
/>
<
bindingRedirect
oldVersion
=
"0.0.0.0-1.5.2.14234"
newVersion
=
"1.5.2.14234"
/>
</
dependentAssembly
>
<
dependentAssembly
>
<
assemblyIdentity
name
=
"Microsoft.Owin"
publicKeyToken
=
"31bf3856ad364e35"
culture
=
"neutral"
/>
<
bindingRedirect
oldVersion
=
"0.0.0.0-4.0.1.0"
newVersion
=
"4.0.1.0"
/>
</
dependentAssembly
>
</
assemblyBinding
>
</
runtime
>
<
system.codedom
>
<
compilers
>
<
compiler
language
=
"c#;cs;csharp"
extension
=
".cs"
type
=
"Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel
=
"4"
compilerOptions
=
"/langversion:6 /nowarn:1659;1699;1701"
/>
<
compiler
language
=
"vb;vbs;visualbasic;vbscript"
extension
=
".vb"
type
=
"Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel
=
"4"
compilerOptions
="/langversion:14 /nowarn:41008 /define:_MYTYPE=\"
Web
\" /optionInfer+"
/>
</
compilers
>
</
system.codedom
>
<
system.webServer
>
<
validation
validateIntegratedModeConfiguration
=
"false"
/>
<
modules
>
<
remove
name
=
"ApplicationInsightsWebTracking"
/>
<
add
name
=
"ApplicationInsightsWebTracking"
type
=
"Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"
preCondition
=
"managedHandler"
/>
</
modules
>
</
system.webServer
>
<
entityFramework
>
<
defaultConnectionFactory
type
=
"System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"
>
<
parameters
>
<
parameter
value
=
"mssqllocaldb"
/>
</
parameters
>
</
defaultConnectionFactory
>
<
providers
>
<
provider
invariantName
=
"System.Data.SqlClient"
type
=
"System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"
/>
</
providers
>
</
entityFramework
>
</
configuration
>
IdentityModels.cs
using
System.Data.Entity;
using
System.Security.Claims;
using
System.Threading.Tasks;
using
Microsoft.AspNet.Identity;
using
Microsoft.AspNet.Identity.EntityFramework;
namespace
Housing_System.Models
{
// You can add profile data for the user by adding more properties to your ApplicationUser class, please visit http://go.microsoft.com/fwlink/?LinkID=317594 to learn more.
public
class
ApplicationUser : IdentityUser
{
public
int
CardNo {
get
;
set
; }
public
string
CardType {
get
;
set
; }
public
string
FullName {
get
;
set
; }
public
async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync(
this
, DefaultAuthenticationTypes.ApplicationCookie);
// Add custom user claims here
return
userIdentity;
}
}
public
class
ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public
ApplicationDbContext()
:
base
(
"DBConnection"
, throwIfV1Schema:
false
)
{
}
public
static
ApplicationDbContext Create()
{
return
new
ApplicationDbContext();
}
public
DbSet<Bed> Beds {
get
;
set
; }
public
DbSet<Employee> Employees {
get
;
set
; }
public
DbSet<Building> Buildings {
get
;
set
; }
public
DbSet<Flat> Flats {
get
;
set
; }
public
DbSet<Floor> Floors {
get
;
set
; }
public
DbSet<Gust> Gusts {
get
;
set
; }
public
DbSet<Room> Rooms {
get
;
set
; }
public
DbSet<student> students {
get
;
set
; }
public
DbSet<Subscriper> Subscripers {
get
;
set
; }
public
DbSet<Subscription> Subscriptions {
get
;
set
; }
public
DbSet<Residence> residences {
get
;
set
; }
public
DbSet<Payment> payments {
get
;
set
; }
}
}
Reply
Answers (
2
)
How to increase performance of Sql ?
Convert STRING DATE TO DATE FORMAT