Web Api Scaffolding - 运行所选代码生成器时出错

时间:2016-02-03 21:12:36

标签: c# entity-framework visual-studio asp.net-web-api

要点: 在Visual Studio 2015(Update 1)中创建新的Web项目时, 我无法使用与实体框架相关的控制器的脚手架工具。

与VS2013 Update 5相同的问题

它返回以下消息:

  

运行所选代码生成器时出错:
  获取类型“failtest.Models.TestModelClass”时出错。   
  尝试重建项目。

我试图重建它,但仍然没有。

任何人都知道我为什么会这样做? 我实际上重新安装了我的Windows 10系统,看看是否可以修复此错误。 - 现在,那个说,无论如何它需要一些强硬的爱,所以我想到它是关于时间的 - 也许它崩溃了,因为我在过去的时间里尝试了大量的节点内容,以及权限错误。 但是在重新安装它之前和之后都出现了错误。 (完成鞭子)

这是Visual Studio 2015 Professional的全新安装 - 基本上没有其他任何内容添加到系统中。

当我第一次开始这篇文章时,我为我的截图创建了一个空白项目,只是为了显示整个过程(下图) - 我觉得我在失去理智。

首先,测试项目突然工作,所以我创建了第二个项目再次测试。 然后它失败了同样的错误。 所以只是为了确认,我删除了第一个有效的项目,并使用与突然工作的名称和文件位置相同的名称和文件位置再次设置(删除所有文件夹和现有项目文件后) - 现在它再次失败。

如何重现:

  1. 创建一个新的“Azure Api App”项目 - 将所有设置保留为默认值(任何项目类型实际上都会产生相同的结果)
  2. New Project

    1. 创建新模型
    2. Model

      1. 构建您的项目(这在Microsoft的一篇文章中提到了使用脚手架的必要条件)

      2. 右键单击“控制器”文件夹,然后选择新建 - >添加新的控制器控制器 - 选择“带有操作的Web Api 2.0控制器,使用实体框架

      3. Add Controller

        1. 填写信息,因为这是一个新项目,我们没有上下文 - 所以点击 + 图标并创建一个新图标。
        2. Fill out information

          1. 产生错误
          2. Error

            编辑:

            Packages.config:

            <?xml version="1.0" encoding="utf-8"?>
            <packages>
              <package id="EntityFramework" version="6.1.3" targetFramework="net452" />
              <package id="Microsoft.AspNet.WebApi" version="5.2.3" targetFramework="net452" />
              <package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net452" />
              <package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net452" />
              <package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.3" targetFramework="net452" />
              <package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net452" />
              <package id="Newtonsoft.Json" version="8.0.2" targetFramework="net452" />
              <package id="Swashbuckle" version="5.3.1" targetFramework="net452" />
              <package id="Swashbuckle.Core" version="5.3.1" targetFramework="net452" />
              <package id="System.IdentityModel.Tokens.Jwt" version="4.0.2.206221351" targetFramework="net452" />
              <package id="WebActivatorEx" version="2.1.0" targetFramework="net452" />
            </packages>
            

            Web.Config:

            <?xml version="1.0" encoding="utf-8"?>
            <!--
              For more information on how to configure your ASP.NET application, please visit
              http://go.microsoft.com/fwlink/?LinkId=301879
              -->
            <configuration>
              <configSections>
                <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
                <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
              </configSections>
              <appSettings></appSettings>
              <system.web>
                <compilation debug="true" targetFramework="4.5.2" />
                <httpRuntime targetFramework="4.5.2" />
              </system.web>
              <system.webServer>
                <handlers>
                  <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
                  <remove name="OPTIONSVerbHandler" />
                  <remove name="TRACEVerbHandler" />
                  <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
                </handlers>
              </system.webServer>
              <runtime>
                <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
                  <dependentAssembly>
                    <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
                    <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
                  </dependentAssembly>
                  <dependentAssembly>
                    <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
                    <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
                  </dependentAssembly>
                  <dependentAssembly>
                    <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
                    <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
                  </dependentAssembly>
                </assemblyBinding>
              </runtime>
              <entityFramework>
                <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
                  <parameters>
                    <parameter value="mssqllocaldb" />
                  </parameters>
                </defaultConnectionFactory>
                <providers>
                  <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
                </providers>
              </entityFramework>
            </configuration>
            

            编辑2 : 我怀疑这是一个EntityFramework问题,因为脚手架适用于不包含EntityFramework的所有内容。

            已经过测试

            • 在Debug和Release config之间切换
            • 更新了所有包和插件
            • 验证了解决方案文件和项目XML
            • 已验证的Web.config
            • 已删除的Bin / Debug文件夹
            • 具有不同项目类型的新项目

            描述相同错误的问题 - 全部经过测试

            我还在aspnet Github问题跟踪器上创建了一个问题。 https://github.com/aspnet/Tooling/issues/411

            并向微软报告了它在Visual Studio中的内部反馈系统。

1 个答案:

答案 0 :(得分:1)

找到解决方案/问题。

我正在使用Panda Antivirus - 在整个过程中,我经常检查Panda是否报告任何被阻止的文件,线程或对系统的任何威胁。并没有报告任何事情 - 所以我排除了防病毒成为问题。

在阅读了另一篇关于其他问题的帖子后,我注意到其中一个解决方案是停用防病毒软件并运行修复。 在尝试了其他一切之后,我做到了这一点。

它再次工作。最后。约20天后。

似乎无需修复安装,因为再次激活防病毒软件会在下次尝试运行脚手架时产生问题。

禁用进程监视器并不能解决问题,并且将所有文件夹添加到AV的例外文件夹中将会有很多保持,所以我可能会切换出我的AV。

希望这可以帮助其他人解决这个问题。

非常感谢 @oleg 试图帮助我在这里!