Summary: When creating a new Web Project in Visual Studio 2015 (Update 1), im unable to use the scaffolding tool for Controllers that relates to Entity Framework.
Same issue occures with VS2013 Update 5
It returns the following message:
There was an error running the selected code generator:
There was an error getting the type "failtest.Models.TestModelClass".
Try rebuilding the project.
I have tried to rebuild it, but still nothing.
Anyone got a clue about why im getting this? I actually re-installed my Windows 10 system to see if this could fix this error. - Now, that beeing said, it was in need for some tough love anyway, so i figgured it was about time - Maybe its crashing because i have tried a vast amount of node stuff in the past time, and permission errors. But the error occured both before and after i re-installed it. (complete whipe)
This is a Fresh install of Visual Studio 2015 Professional - Basically nothing else has been added to the system yet.
When i first started this post, i created a blank project for my screenshots just to show the entire process (below) - And i tought i was loosing my mind.
At first, the testproject suddenly worked, so i created a second project to test again. And then it failed with the same error. So just to confirm, i deleted the first project that worked, and set it up again with the exact same name and file location as the one that suddenly worked ( after deleting all folders and existing project files ) - And now it keeps failing again.
How to reproduce:
- Create a new "Azure Api App" project - Leave all settings as default (Any project type will produce the same result actually)
- Create a new Model
Build your project (this is mentioned on an article from Microsoft to be nesesary to use the scaffolder)
Add a new Controller by right clicking the "Controllers" folder, and selecting New -> Controller - Select "Web Api 2.0 controller with actions, using Entity Framework"
- Fill out the information, since this is a new project, we dont have a context - so click the + icon and create a new one.
- Error is produced
EDIT:
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>
EDIT 2: I Suspect that this is an EntityFramework issue, as the scaffolder works for everything that doesnt include EntityFramework.
Already tested
- Switch between Debug and Release config
- Updated all packages and plugins
- Verified the solution file and project XML
- Verified Web.config
- Deleted Bin / Debug folder
- New project with different project types
Issues describing the same error - All tested
- Scaffolding/Auto code generator completely broken?
- There was an error running the selected code generator...
- How do i add a controller to asp.net MVC....
- External: There was an error running the selected code generator
- External: VS2013 scaffolding error
- Scaffolding controller doesn't work with visual studio 2013 update 2
I also created an issue on this on the aspnet Github issue tracker. https://github.com/aspnet/Tooling/issues/411
And reported it to Microsoft trought the internal Feedback system in Visual Studio.