How to fix System.InvalidOperationException in mvc 5 in index controllerHow does database indexing work?Multiple Indexes vs Multi-Column IndexesCan an ASP.NET MVC controller return an Image?In MVC, how do I return a string result?Subsonic 2.2 ASP.NET MVC Unrecognized configuration sectionASP.NET MVC 2 InputExtensions different on server than local machineFile Upload ASP.NET MVC 3.0How should a model be structured in MVC?Not able to deploy ASP.NET MVC 3System.Codedeom alternative solution in Asp .net mvc web.config file
In Toy Story, are toys the only inanimate objects that become alive? And if so, why?
Why do modes sound so different, although they are basically the same as a mode of another scale?
When do we use "no women" instead of "no woman"?
How to have the "Restore Missing Files" function from Nautilus without installing Nautilus?
How do you manage to study and have a balance in your life at the same time?
How would a disabled person earn their living in a medieval-type town?
How to use a tikzpicture as a node shape
How were US credit cards verified in-store in the 1980's?
Should we run PBKDF2 for every plaintext to be protected or should we run PBKDF2 only once?
Get rows that exist exactly once per day for a given period
What is the motivation behind designing a control stick that does not move?
Why do we need explainable AI?
Cheap oscilloscope showing 16 MHz square wave
What happens if you just start drawing from the Deck of Many Things without declaring any number of cards?
Given a specific computer system, is it possible to estimate the actual precise run time of a piece of Assembly code
If the government illegally doesn't ask for article 50 extension, can parliament do it instead?
The Justice Thought & System & its Morals?
Missing $ inserted. Extra }, or forgotten $. Missing } inserted
Can authors email you PDFs of their textbook for free?
Is torque as fundamental a concept as force?
Different past tense for various *et words
Am I required to correct my opponent's assumptions about my morph creatures?
Why wasn't Linda Hamilton in T3?
Would there be balance issues if I allowed opportunity attacks against any creature, not just hostile ones?
How to fix System.InvalidOperationException in mvc 5 in index controller
How does database indexing work?Multiple Indexes vs Multi-Column IndexesCan an ASP.NET MVC controller return an Image?In MVC, how do I return a string result?Subsonic 2.2 ASP.NET MVC Unrecognized configuration sectionASP.NET MVC 2 InputExtensions different on server than local machineFile Upload ASP.NET MVC 3.0How should a model be structured in MVC?Not able to deploy ASP.NET MVC 3System.Codedeom alternative solution in Asp .net mvc web.config file
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I'm learning to create a web application in asp.net and following this documentation :
https://docs.microsoft.com/en-us/aspnet/mvc/overview/getting-started/getting-started-with-ef-using-mvc/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application
after completing all the step i'm getting this error and i don't know what to do with it
Error:
System.InvalidOperationException: 'Failed to set database initializer of
type 'Clothing_Store.DAL.CustomerInit, Clothing_Store' for DbContext type '
Clothing_Store.DAL.ShopContext, Clothing_Store' specified in the
application configuration. See inner exception for details.'
InnerException:
InnerException "Could not load file or assembly 'Clothing_Store' or one of its dependencies. The system cannot find the file specified.":"Clothing_Store" System.Exception System.IO.FileNotFoundException
ShopContext:
using Clothing_Store.Models;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Linq;
using System.Web;
namespace Clothing_Store.DAL
public class ShopContext: DbContext
public ShopContext() : base("ShopContext")
public DbSet<customer> Customers get; set;
protected override void OnModelCreating(DbModelBuilder modelBuilder)
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
CustomerInit:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Clothing_Store.Models;
namespace Clothing_Store.DAL
public class CustomerInit : System.Data.Entity.DropCreateDatabaseIfModelChanges<ShopContext>
protected override void Seed(ShopContext context)
var customers = new List<customer>
new customerc_name="Carson",email="ab@g.com",pass="abcd",phone="012",
new customerc_name="mason",email="abcd@g.com",pass="dabcd",phone="0122"
;
customers.ForEach(s => context.Customers.Add(s));
context.SaveChanges();
WebConfig:
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
https://go.microsoft.com/fwlink/?LinkId=301880
-->
<configuration>
<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>
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)MSSQLLocalDB;Initial Catalog=aspnet-Clothing_Store-fefdc1f0-bd81-4ce9-b712-93a062e01031;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnet-Clothing_Store-fefdc1f0-bd81-4ce9-b712-93a062e01031.mdf" providerName="System.Data.SqlClient" />
<add name="ShopContext" connectionString="Data Source=(LocalDb)MSSQLLocalDB;Initial Catalog=Clothing_Store1;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|Clothing_Store1.mdf" providerName="System.Data.SqlClient" />
</connectionStrings>
<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.6.1" />
<httpRuntime targetFramework="4.6.1" />
</system.web>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" />
<bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Diagnostics.DiagnosticSource" publicKeyToken="cc7b13ffcd2ddd51" />
<bindingRedirect oldVersion="0.0.0.0-4.0.2.1" newVersion="4.0.2.1" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
</dependentAssembly>
<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.4.0" newVersion="5.2.4.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.webServer>
<modules>
<remove name="TelemetryCorrelationHttpModule" />
<add name="TelemetryCorrelationHttpModule" type="Microsoft.AspNet.TelemetryCorrelation.TelemetryCorrelationHttpModule, Microsoft.AspNet.TelemetryCorrelation" preCondition="integratedMode,managedHandler" />
</modules>
</system.webServer>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE="Web" /optionInfer+" />
</compilers>
</system.codedom>
<entityFramework>
<contexts>
<context type=" Clothing_Store.DAL.ShopContext, Clothing_Store">
<databaseInitializer type="Clothing_Store.DAL.CustomerInit, Clothing_Store" />
</context>
</contexts>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
asp.net-mvc database asp.net-mvc-5 model
add a comment |
I'm learning to create a web application in asp.net and following this documentation :
https://docs.microsoft.com/en-us/aspnet/mvc/overview/getting-started/getting-started-with-ef-using-mvc/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application
after completing all the step i'm getting this error and i don't know what to do with it
Error:
System.InvalidOperationException: 'Failed to set database initializer of
type 'Clothing_Store.DAL.CustomerInit, Clothing_Store' for DbContext type '
Clothing_Store.DAL.ShopContext, Clothing_Store' specified in the
application configuration. See inner exception for details.'
InnerException:
InnerException "Could not load file or assembly 'Clothing_Store' or one of its dependencies. The system cannot find the file specified.":"Clothing_Store" System.Exception System.IO.FileNotFoundException
ShopContext:
using Clothing_Store.Models;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Linq;
using System.Web;
namespace Clothing_Store.DAL
public class ShopContext: DbContext
public ShopContext() : base("ShopContext")
public DbSet<customer> Customers get; set;
protected override void OnModelCreating(DbModelBuilder modelBuilder)
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
CustomerInit:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Clothing_Store.Models;
namespace Clothing_Store.DAL
public class CustomerInit : System.Data.Entity.DropCreateDatabaseIfModelChanges<ShopContext>
protected override void Seed(ShopContext context)
var customers = new List<customer>
new customerc_name="Carson",email="ab@g.com",pass="abcd",phone="012",
new customerc_name="mason",email="abcd@g.com",pass="dabcd",phone="0122"
;
customers.ForEach(s => context.Customers.Add(s));
context.SaveChanges();
WebConfig:
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
https://go.microsoft.com/fwlink/?LinkId=301880
-->
<configuration>
<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>
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)MSSQLLocalDB;Initial Catalog=aspnet-Clothing_Store-fefdc1f0-bd81-4ce9-b712-93a062e01031;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnet-Clothing_Store-fefdc1f0-bd81-4ce9-b712-93a062e01031.mdf" providerName="System.Data.SqlClient" />
<add name="ShopContext" connectionString="Data Source=(LocalDb)MSSQLLocalDB;Initial Catalog=Clothing_Store1;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|Clothing_Store1.mdf" providerName="System.Data.SqlClient" />
</connectionStrings>
<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.6.1" />
<httpRuntime targetFramework="4.6.1" />
</system.web>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" />
<bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Diagnostics.DiagnosticSource" publicKeyToken="cc7b13ffcd2ddd51" />
<bindingRedirect oldVersion="0.0.0.0-4.0.2.1" newVersion="4.0.2.1" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
</dependentAssembly>
<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.4.0" newVersion="5.2.4.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.webServer>
<modules>
<remove name="TelemetryCorrelationHttpModule" />
<add name="TelemetryCorrelationHttpModule" type="Microsoft.AspNet.TelemetryCorrelation.TelemetryCorrelationHttpModule, Microsoft.AspNet.TelemetryCorrelation" preCondition="integratedMode,managedHandler" />
</modules>
</system.webServer>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE="Web" /optionInfer+" />
</compilers>
</system.codedom>
<entityFramework>
<contexts>
<context type=" Clothing_Store.DAL.ShopContext, Clothing_Store">
<databaseInitializer type="Clothing_Store.DAL.CustomerInit, Clothing_Store" />
</context>
</contexts>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
asp.net-mvc database asp.net-mvc-5 model
add a comment |
I'm learning to create a web application in asp.net and following this documentation :
https://docs.microsoft.com/en-us/aspnet/mvc/overview/getting-started/getting-started-with-ef-using-mvc/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application
after completing all the step i'm getting this error and i don't know what to do with it
Error:
System.InvalidOperationException: 'Failed to set database initializer of
type 'Clothing_Store.DAL.CustomerInit, Clothing_Store' for DbContext type '
Clothing_Store.DAL.ShopContext, Clothing_Store' specified in the
application configuration. See inner exception for details.'
InnerException:
InnerException "Could not load file or assembly 'Clothing_Store' or one of its dependencies. The system cannot find the file specified.":"Clothing_Store" System.Exception System.IO.FileNotFoundException
ShopContext:
using Clothing_Store.Models;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Linq;
using System.Web;
namespace Clothing_Store.DAL
public class ShopContext: DbContext
public ShopContext() : base("ShopContext")
public DbSet<customer> Customers get; set;
protected override void OnModelCreating(DbModelBuilder modelBuilder)
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
CustomerInit:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Clothing_Store.Models;
namespace Clothing_Store.DAL
public class CustomerInit : System.Data.Entity.DropCreateDatabaseIfModelChanges<ShopContext>
protected override void Seed(ShopContext context)
var customers = new List<customer>
new customerc_name="Carson",email="ab@g.com",pass="abcd",phone="012",
new customerc_name="mason",email="abcd@g.com",pass="dabcd",phone="0122"
;
customers.ForEach(s => context.Customers.Add(s));
context.SaveChanges();
WebConfig:
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
https://go.microsoft.com/fwlink/?LinkId=301880
-->
<configuration>
<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>
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)MSSQLLocalDB;Initial Catalog=aspnet-Clothing_Store-fefdc1f0-bd81-4ce9-b712-93a062e01031;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnet-Clothing_Store-fefdc1f0-bd81-4ce9-b712-93a062e01031.mdf" providerName="System.Data.SqlClient" />
<add name="ShopContext" connectionString="Data Source=(LocalDb)MSSQLLocalDB;Initial Catalog=Clothing_Store1;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|Clothing_Store1.mdf" providerName="System.Data.SqlClient" />
</connectionStrings>
<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.6.1" />
<httpRuntime targetFramework="4.6.1" />
</system.web>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" />
<bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Diagnostics.DiagnosticSource" publicKeyToken="cc7b13ffcd2ddd51" />
<bindingRedirect oldVersion="0.0.0.0-4.0.2.1" newVersion="4.0.2.1" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
</dependentAssembly>
<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.4.0" newVersion="5.2.4.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.webServer>
<modules>
<remove name="TelemetryCorrelationHttpModule" />
<add name="TelemetryCorrelationHttpModule" type="Microsoft.AspNet.TelemetryCorrelation.TelemetryCorrelationHttpModule, Microsoft.AspNet.TelemetryCorrelation" preCondition="integratedMode,managedHandler" />
</modules>
</system.webServer>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE="Web" /optionInfer+" />
</compilers>
</system.codedom>
<entityFramework>
<contexts>
<context type=" Clothing_Store.DAL.ShopContext, Clothing_Store">
<databaseInitializer type="Clothing_Store.DAL.CustomerInit, Clothing_Store" />
</context>
</contexts>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
asp.net-mvc database asp.net-mvc-5 model
I'm learning to create a web application in asp.net and following this documentation :
https://docs.microsoft.com/en-us/aspnet/mvc/overview/getting-started/getting-started-with-ef-using-mvc/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application
after completing all the step i'm getting this error and i don't know what to do with it
Error:
System.InvalidOperationException: 'Failed to set database initializer of
type 'Clothing_Store.DAL.CustomerInit, Clothing_Store' for DbContext type '
Clothing_Store.DAL.ShopContext, Clothing_Store' specified in the
application configuration. See inner exception for details.'
InnerException:
InnerException "Could not load file or assembly 'Clothing_Store' or one of its dependencies. The system cannot find the file specified.":"Clothing_Store" System.Exception System.IO.FileNotFoundException
ShopContext:
using Clothing_Store.Models;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Linq;
using System.Web;
namespace Clothing_Store.DAL
public class ShopContext: DbContext
public ShopContext() : base("ShopContext")
public DbSet<customer> Customers get; set;
protected override void OnModelCreating(DbModelBuilder modelBuilder)
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
CustomerInit:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Clothing_Store.Models;
namespace Clothing_Store.DAL
public class CustomerInit : System.Data.Entity.DropCreateDatabaseIfModelChanges<ShopContext>
protected override void Seed(ShopContext context)
var customers = new List<customer>
new customerc_name="Carson",email="ab@g.com",pass="abcd",phone="012",
new customerc_name="mason",email="abcd@g.com",pass="dabcd",phone="0122"
;
customers.ForEach(s => context.Customers.Add(s));
context.SaveChanges();
WebConfig:
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
https://go.microsoft.com/fwlink/?LinkId=301880
-->
<configuration>
<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>
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)MSSQLLocalDB;Initial Catalog=aspnet-Clothing_Store-fefdc1f0-bd81-4ce9-b712-93a062e01031;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnet-Clothing_Store-fefdc1f0-bd81-4ce9-b712-93a062e01031.mdf" providerName="System.Data.SqlClient" />
<add name="ShopContext" connectionString="Data Source=(LocalDb)MSSQLLocalDB;Initial Catalog=Clothing_Store1;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|Clothing_Store1.mdf" providerName="System.Data.SqlClient" />
</connectionStrings>
<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.6.1" />
<httpRuntime targetFramework="4.6.1" />
</system.web>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" />
<bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Diagnostics.DiagnosticSource" publicKeyToken="cc7b13ffcd2ddd51" />
<bindingRedirect oldVersion="0.0.0.0-4.0.2.1" newVersion="4.0.2.1" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
</dependentAssembly>
<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.4.0" newVersion="5.2.4.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.webServer>
<modules>
<remove name="TelemetryCorrelationHttpModule" />
<add name="TelemetryCorrelationHttpModule" type="Microsoft.AspNet.TelemetryCorrelation.TelemetryCorrelationHttpModule, Microsoft.AspNet.TelemetryCorrelation" preCondition="integratedMode,managedHandler" />
</modules>
</system.webServer>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE="Web" /optionInfer+" />
</compilers>
</system.codedom>
<entityFramework>
<contexts>
<context type=" Clothing_Store.DAL.ShopContext, Clothing_Store">
<databaseInitializer type="Clothing_Store.DAL.CustomerInit, Clothing_Store" />
</context>
</contexts>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
asp.net-mvc database asp.net-mvc-5 model
asp.net-mvc database asp.net-mvc-5 model
asked Mar 27 at 17:45
AlwaysaNoobAlwaysaNoob
85 bronze badges
85 bronze badges
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
In your web.config
, there is an extra space added in the <context type="
<context type=" Clothing_Store.DAL.ShopContext, Clothing_Store">
^
Can you please remove that and re-run the application.
didn't work. Showing the same error.
– AlwaysaNoob
Mar 27 at 18:26
add a comment |
Have you tried to "rebuild" the application instead of using "build"? You can also try to "clean" the project first and then "build". Does the project "Clothing_Store" have the EntityFramework dlls? Also check if the Clothing_Store.dll is created in the bin folder of the Asp.net MVC application.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55383549%2fhow-to-fix-system-invalidoperationexception-in-mvc-5-in-index-controller%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
In your web.config
, there is an extra space added in the <context type="
<context type=" Clothing_Store.DAL.ShopContext, Clothing_Store">
^
Can you please remove that and re-run the application.
didn't work. Showing the same error.
– AlwaysaNoob
Mar 27 at 18:26
add a comment |
In your web.config
, there is an extra space added in the <context type="
<context type=" Clothing_Store.DAL.ShopContext, Clothing_Store">
^
Can you please remove that and re-run the application.
didn't work. Showing the same error.
– AlwaysaNoob
Mar 27 at 18:26
add a comment |
In your web.config
, there is an extra space added in the <context type="
<context type=" Clothing_Store.DAL.ShopContext, Clothing_Store">
^
Can you please remove that and re-run the application.
In your web.config
, there is an extra space added in the <context type="
<context type=" Clothing_Store.DAL.ShopContext, Clothing_Store">
^
Can you please remove that and re-run the application.
answered Mar 27 at 18:12
ArulkumarArulkumar
10.9k12 gold badges37 silver badges52 bronze badges
10.9k12 gold badges37 silver badges52 bronze badges
didn't work. Showing the same error.
– AlwaysaNoob
Mar 27 at 18:26
add a comment |
didn't work. Showing the same error.
– AlwaysaNoob
Mar 27 at 18:26
didn't work. Showing the same error.
– AlwaysaNoob
Mar 27 at 18:26
didn't work. Showing the same error.
– AlwaysaNoob
Mar 27 at 18:26
add a comment |
Have you tried to "rebuild" the application instead of using "build"? You can also try to "clean" the project first and then "build". Does the project "Clothing_Store" have the EntityFramework dlls? Also check if the Clothing_Store.dll is created in the bin folder of the Asp.net MVC application.
add a comment |
Have you tried to "rebuild" the application instead of using "build"? You can also try to "clean" the project first and then "build". Does the project "Clothing_Store" have the EntityFramework dlls? Also check if the Clothing_Store.dll is created in the bin folder of the Asp.net MVC application.
add a comment |
Have you tried to "rebuild" the application instead of using "build"? You can also try to "clean" the project first and then "build". Does the project "Clothing_Store" have the EntityFramework dlls? Also check if the Clothing_Store.dll is created in the bin folder of the Asp.net MVC application.
Have you tried to "rebuild" the application instead of using "build"? You can also try to "clean" the project first and then "build". Does the project "Clothing_Store" have the EntityFramework dlls? Also check if the Clothing_Store.dll is created in the bin folder of the Asp.net MVC application.
answered Mar 28 at 1:22
dev4sdev4s
315 bronze badges
315 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55383549%2fhow-to-fix-system-invalidoperationexception-in-mvc-5-in-index-controller%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown