【问题标题】:Could not load file or assembly or its dependencies. The system cannot find the file specified无法加载文件或程序集或其依赖项。该系统找不到指定的文件
【发布时间】:2013-12-18 09:18:11
【问题描述】:

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

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

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

System.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 类中出现异常:

【问题讨论】:

  • 我还没有制作它,因为在教程中它被指定为制作一个 dll。 @Tobberoth
  • 您的命名空间是否命名为 Vag_Infotech?似乎很难找到它。你能发布你的 CollegeDbContext 类的代码吗?或者可能是 DAL 文件夹中的初始化程序代码,因为这似乎是关键问题。
  • @Tobberoth 是的。我在创建应用程序时犯了一个错误,我输入了应用程序 Vag Infotech 的名称。
  • 嗯,CollegeDbContext 对我来说看起来不错。。您可以使用“在文件中查找”来搜索 Contoso,看看是否有遗漏的地方将 ContosoUniversity 更改为 Val_Infotech?
  • 看着它@Tobberoth

标签: c# asp.net visual-studio-2013 asp.net-mvc-5


【解决方案1】:

好消息,

我解决了我的问题。我从 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());
    }
}

我只是在Application_Start() 中初始化我的CollegeDatabaseInitializer()。但请注意从Web.Config文件中删除&lt;contexts&gt;。谢谢。

【讨论】:

  • 不确定是什么导致了这个问题,因为我所做的只是从教程中复制粘贴文本。无论如何,这也对我有用。我想知道它是否与在 Mac 上运行并行有关?
  • @Nimit Joshi 它对我有用,但为什么这是 web.config 中 Context 标签的问题?
【解决方案2】:

以管理员身份运行 VisualStudio 2012 的 Developer CommandPropmpt,然后对其运行命令。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-05-10
    • 2020-01-21
    • 2018-11-29
    • 2016-12-15
    • 2018-12-22
    相关资源
    最近更新 更多