Nimit Joshi
Nimit Joshi

Reputation: 1046

Could not load file or assembly or its dependencies. The system cannot find the file specified

I'm following the tutorial as shown in the link below:

Creating an Entity Framework data model for ASP.NET MVC application

But while running the application, the following exception comes:

System.IO.FileNotFoundException: Could not load file or assembly 'Vag_Infotech' or one of its dependencies. The system cannot find the file specified.

My web.config file is as follows:

<connectionStrings>
  <add name="CollegeDbContext" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=VInfotech;Integrated Security=SSPI" providerName="System.Data.SqlClient"/>
</connectionStrings>

<contexts>
  <context type="Vag_Infotech.DAL.CollegeDbContext, Vag_Infotech">
    <databaseInitializer type="Vag_Infotech.DAL.CollegeDatabaseInitializer, Vag_Infotech"></databaseInitializer>
  </context>
</contexts>

CollegeDbContext Class:

namespace Vag_Infotech.DAL
{
public class CollegeDbContext : DbContext 
{
    public CollegeDbContext()
        : base("CollegeDbContext")
    {

    }

    public DbSet<Student> Students { get; set; }
    public DbSet<Course> Courses { get; set; }
    public DbSet<Enrollment> Enrollments { get; set; }
    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
    }
}

}

The exception comes in the StudentController.cs class:

enter image description here

Upvotes: 2

Views: 3613

Answers (2)

Miank
Miank

Reputation: 105

Run Developer CommandPropmpt for VisualStudio 2012 as Administrator and then run the command over it.

Upvotes: 0

Nimit Joshi
Nimit Joshi

Reputation: 1046

Great News,

I solved my problem. I initialized my DatabaseInitializer from the Global.asax file. Take a look on the code below:

public class MvcApplication : System.Web.HttpApplication
{
    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);
        Database.SetInitializer(new CollegeDatabaseInitializer());
    }
}

I simply initialize my CollegeDatabaseInitializer() in the Application_Start(). But please note that remove the <contexts> from the Web.Configfile. Thanks.

Upvotes: 6

Related Questions