【问题标题】:The templates had the following errors when running模板在运行时出现以下错误
【发布时间】:2013-05-21 09:16:27
【问题描述】:

当我尝试在 ASP.NET MVC 3 中添加强类型视图时,我收到以下错误:

我重新启动 Visual Studio,重建项目,再次尝试添加视图并得到以下结果:

我的模特:

public class SimpleModel
{
    public int ID { get; set; }
    public string Name { get; set; }
    public bool IsActive { get; set; }
}

我的控制器:

public class TestController : Controller
{
    public ActionResult Test()
    {
        return View(new SimpleModel());
    }
}

问题是环境范围的(我创建了一个新项目并尝试添加视图,结果相同)并且无法通过重新启动 Visual Studio 或我的开发机器来解决。
编辑:只需重新安装 ASP.NET 和 Web Tools 2012.2 即可解决问题。

【问题讨论】:

  • 是否都添加了System.ComponentModel.DataAnnotations.dllSystem.Core.dll 作为对项目的引用?
  • @RobH System.ComponentModel.DataAnnotations 被引用,但 System.Core 不是。当我尝试手动添加它时,我收到以下错误:无法添加对“System.Core”的引用。该组件已被构建系统自动引用。
  • 看起来Visual Studio 无法访问System.ComponentModel.DataAnnotations.dll,你能把它安装到GAC 中吗?
  • 或者我认为您可以使用 ProcessMonitor 找出 Visual Studio 尝试搜索该 dll 的确切位置。

标签: c# asp.net-mvc visual-studio t4 strongly-typed-view


【解决方案1】:

使用process monitor,我发现,至少在我的机器上,Visual Studio 会从 GAC 加载 System.ComponentModel.DataAnnotations.dll

12:43:12.6470833 PM devenv.exe 772 加载映像 C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.ComponentModel.DataAnnotations\v4.0_4.0.0.0__31bf3856ad364e35\System.ComponentModel.DataAnnotations.dll 成功图片库:0x5f7b0000,图片大小:0x1e000

我所做的是我已经启动了进程监视器,添加过滤器以仅从 devenv.exe 捕获事件,然后尝试为 MVC 3 应用程序构建视图,然后在捕获的事件中搜索 System.ComponentModel.DataAnnotations.dll

【讨论】:

  • 我按照你的描述做了,我得到了 C:\Windows\Microsoft.Net\assembly\GAC_32\System.ComponentModel.DataAnnotations\v4.0_4.0.0.0__31bf3856ad364e35\ 的“PATH NOT FOUND” System.ComponentModel.DataAnnotations.dll 和 C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.ComponentModel.DataAnnotations\v4.0_4.0.0.0__31bf3856ad364e35\System.ComponentModel.DataAnnotations.dll 的“SUCCESS”
  • 尝试进一步搜索,我发现它也从不同的位置加载,例如 C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.ComponentModel .DataAnnotations.dll
猜你喜欢
  • 1970-01-01
  • 2021-08-31
  • 1970-01-01
  • 2016-11-26
  • 1970-01-01
  • 1970-01-01
  • 2017-03-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多