2013-12-18 37 views
2

我下面的教程如下图所示链接:无法加载文件或程序集或其依赖项。该系统找不到指定的文件

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

但在运行应用程序,以下异常谈到:

系统。 IO.FileNotFoundException:无法加载文件或程序集“Vag_Infotech”或其某个依赖项。该系统找不到指定的文件。

我的web.config文件如下:

<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类:

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>(); 
    } 
} 

}

唯一的例外来自于StudentController.cs类:

enter image description here

+0

我还没有做到这一点,因为在本教程中,它被指定为制作一个dll。 @Tobberoth –

+2

您的命名空间名为Vag_Infotech?它似乎有问题找到它。你可以发布你的CollegeDbContext类的代码吗?或者可能是来自DAL文件夹的初始化程序代码,因为这似乎是关键问题。 – Tobberoth

+0

@Tobberoth是的。我在创建应用程序时犯了一个错误,我输入了应用程序Vag Infotech的名称。 –

回答

6

好消息,

我解决了我的问题。我从Global.asax文件初始化我的DatabaseInitializer。采取下面的代码一看:

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()); 
    } 
} 

我只是初始化我CollegeDatabaseInitializer()Application_Start()。但请注意,从Web.Config文件中删除<contexts>。谢谢。

+0

不知道是什么原因造成了这个问题,因为我所做的只是从教程中复制粘贴文本。反正这也适用于我。我想知道它是否与在Mac上运行相似程序有关? – snapper

+0

@Nimit Joshi它为我工作,但为什么它是在web.config中的上下文标记问题? –

0

以管理员身份运行Developer Studio CommandPropmpt for VisualStudio 2012,然后在其上运行命令。

相关问题