2013-12-18 39 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,然後在其上運行命令。

相關問題