gpt4 book ai didi

c# - 无法加载文件或程序集或其依赖项。该系统找不到指定的文件

转载 作者:行者123 更新时间:2023-12-02 19:35:20 24 4
gpt4 key购买 nike

我正在按照以下链接所示的教程进行操作:

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

但是在运行应用程序时,出现以下异常:

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

我的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

最佳答案

好消息,

我解决了我的问题。我从 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() 。但请注意,删除 <contexts>来自Web.Config文件。谢谢。

关于c# - 无法加载文件或程序集或其依赖项。该系统找不到指定的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20653931/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com